1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

use in and startswith() instead of find()

This commit is contained in:
Kelly Brazil
2020-04-04 17:10:46 -07:00
parent a9c59ef9fc
commit c174d3de18

View File

@ -313,7 +313,7 @@ import jc.utils
class info(): class info():
version = '1.2' version = '1.3'
description = 'netstat command parser' description = 'netstat command parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -498,14 +498,14 @@ def parse_post(raw_data):
if 'proto' in entry and 'kind' in entry: if 'proto' in entry and 'kind' in entry:
if entry['kind'] == 'network': if entry['kind'] == 'network':
if entry['proto'].find('tcp') != -1: if 'tcp' in entry['proto']:
entry['transport_protocol'] = 'tcp' entry['transport_protocol'] = 'tcp'
elif entry['proto'].find('udp') != -1: elif 'udp' in entry['proto']:
entry['transport_protocol'] = 'udp' entry['transport_protocol'] = 'udp'
else: else:
entry['transport_protocol'] = None entry['transport_protocol'] = None
if entry['proto'].find('6') != -1: if '6' in entry['proto']:
entry['network_protocol'] = 'ipv6' entry['network_protocol'] = 'ipv6'
else: else:
entry['network_protocol'] = 'ipv4' entry['network_protocol'] = 'ipv4'
@ -542,19 +542,19 @@ def parse(data, raw=False, quiet=False):
for line in cleandata: for line in cleandata:
if line.find('Active Internet') == 0: if line.startswith('Active Internet'):
network_list = [] network_list = []
network = True network = True
socket = False socket = False
continue continue
if line.find('Active UNIX') == 0: if line.startswith('Active UNIX'):
socket_list = [] socket_list = []
network = False network = False
socket = True socket = True
continue continue
if line.find('Proto') == 0: if line.startswith('Proto'):
header_text = normalize_headers(line) header_text = normalize_headers(line)
headers = header_text.split() headers = header_text.split()
continue continue