mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
more linting
This commit is contained in:
parent
b175b705ce
commit
c26e50e694
@ -32,7 +32,7 @@ tcpdump "tcp[tcpflags] & tcp-syn != 0" and port 4505 and "tcp[tcpflags] & tcp-ac
|
|||||||
For Port 4506
|
For Port 4506
|
||||||
tcpdump "tcp[tcpflags] & tcp-syn != 0" and port 4506 and "tcp[tcpflags] & tcp-ack == 0"
|
tcpdump "tcp[tcpflags] & tcp-syn != 0" and port 4506 and "tcp[tcpflags] & tcp-ack == 0"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
import pcapy
|
import pcapy
|
||||||
@ -61,9 +61,9 @@ class ArgParser(object):
|
|||||||
default='eth0',
|
default='eth0',
|
||||||
dest='iface',
|
dest='iface',
|
||||||
required=False,
|
required=False,
|
||||||
help=('the interface to dump the'
|
help=('the interface to dump the'
|
||||||
'master runs on(default:eth0)'))
|
'master runs on(default:eth0)'))
|
||||||
|
|
||||||
self.main_parser.add_argument('-n',
|
self.main_parser.add_argument('-n',
|
||||||
type=int,
|
type=int,
|
||||||
default=5,
|
default=5,
|
||||||
@ -120,9 +120,9 @@ class PCAPParser(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
(header, packet) = cap.next()
|
(header, packet) = cap.next()
|
||||||
|
|
||||||
eth_length, eth_protocol = self.parse_ether(packet)
|
eth_length, eth_protocol = self.parse_ether(packet)
|
||||||
|
|
||||||
# Parse IP packets, IP Protocol number = 8
|
# Parse IP packets, IP Protocol number = 8
|
||||||
if eth_protocol == 8 :
|
if eth_protocol == 8 :
|
||||||
#Parse IP header
|
#Parse IP header
|
||||||
@ -146,12 +146,12 @@ class PCAPParser(object):
|
|||||||
parse ethernet_header and return size and protocol
|
parse ethernet_header and return size and protocol
|
||||||
'''
|
'''
|
||||||
eth_length = 14
|
eth_length = 14
|
||||||
|
|
||||||
eth_header = packet[:eth_length]
|
eth_header = packet[:eth_length]
|
||||||
eth = unpack('!6s6sH' , eth_header)
|
eth = unpack('!6s6sH' , eth_header)
|
||||||
eth_protocol = socket.ntohs(eth[2])
|
eth_protocol = socket.ntohs(eth[2])
|
||||||
return eth_length, eth_protocol
|
return eth_length, eth_protocol
|
||||||
|
|
||||||
def parse_ip(self, packet, eth_length):
|
def parse_ip(self, packet, eth_length):
|
||||||
'''
|
'''
|
||||||
parse ip_header and return all ip data fields
|
parse ip_header and return all ip data fields
|
||||||
@ -159,33 +159,33 @@ class PCAPParser(object):
|
|||||||
#Parse IP header
|
#Parse IP header
|
||||||
#take first 20 characters for the ip header
|
#take first 20 characters for the ip header
|
||||||
ip_header = packet[eth_length:20+eth_length]
|
ip_header = packet[eth_length:20+eth_length]
|
||||||
|
|
||||||
#now unpack them :)
|
#now unpack them :)
|
||||||
iph = unpack('!BBHHHBBH4s4s' , ip_header)
|
iph = unpack('!BBHHHBBH4s4s' , ip_header)
|
||||||
|
|
||||||
version_ihl = iph[0]
|
version_ihl = iph[0]
|
||||||
version = version_ihl >> 4
|
version = version_ihl >> 4
|
||||||
ihl = version_ihl & 0xF
|
ihl = version_ihl & 0xF
|
||||||
|
|
||||||
iph_length = ihl * 4
|
iph_length = ihl * 4
|
||||||
|
|
||||||
ttl = iph[5]
|
ttl = iph[5]
|
||||||
protocol = iph[6]
|
protocol = iph[6]
|
||||||
s_addr = socket.inet_ntoa(iph[8])
|
s_addr = socket.inet_ntoa(iph[8])
|
||||||
d_addr = socket.inet_ntoa(iph[9])
|
d_addr = socket.inet_ntoa(iph[9])
|
||||||
|
|
||||||
return [version_ihl,
|
return [version_ihl,
|
||||||
version,
|
version,
|
||||||
ihl,
|
ihl,
|
||||||
iph_length,
|
iph_length,
|
||||||
ttl,
|
ttl,
|
||||||
protocol,
|
protocol,
|
||||||
s_addr,
|
s_addr,
|
||||||
d_addr]
|
d_addr]
|
||||||
|
|
||||||
def parse_tcp(self, packet, iph_length, eth_length):
|
def parse_tcp(self, packet, iph_length, eth_length):
|
||||||
'''
|
'''
|
||||||
parse tcp_data and return source_port,
|
parse tcp_data and return source_port,
|
||||||
dest_port and actual packet data
|
dest_port and actual packet data
|
||||||
'''
|
'''
|
||||||
p_len = iph_length + eth_length
|
p_len = iph_length + eth_length
|
||||||
@ -219,13 +219,13 @@ class SaltNetstat(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def proc_tcp(self):
|
def proc_tcp(self):
|
||||||
'''
|
'''
|
||||||
Read the table of tcp connections & remove header
|
Read the table of tcp connections & remove header
|
||||||
'''
|
'''
|
||||||
with open('/proc/net/tcp', 'r') as tcp_f:
|
with open('/proc/net/tcp', 'r') as tcp_f:
|
||||||
content = tcp_f.readlines()
|
content = tcp_f.readlines()
|
||||||
content.pop(0)
|
content.pop(0)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def hex2dec(self, hex_s):
|
def hex2dec(self, hex_s):
|
||||||
'''
|
'''
|
||||||
@ -283,7 +283,7 @@ class SaltNetstat(object):
|
|||||||
yield (len(ips['ips/4505']), len(ips['ips/4506']))
|
yield (len(ips['ips/4505']), len(ips['ips/4506']))
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
def filter_new_cons(packet):
|
def filter_new_cons(packet):
|
||||||
'''
|
'''
|
||||||
filter packets by there tcp-state and
|
filter packets by there tcp-state and
|
||||||
@ -325,7 +325,7 @@ def filter_new_cons(packet):
|
|||||||
# track closing connections
|
# track closing connections
|
||||||
elif 'FIN' in flags:
|
elif 'FIN' in flags:
|
||||||
return 12
|
return 12
|
||||||
|
|
||||||
elif packet['tcp']['d_port'] == 4506:
|
elif packet['tcp']['d_port'] == 4506:
|
||||||
# track new connections
|
# track new connections
|
||||||
if 'SYN' in flags and len(flags) == 1:
|
if 'SYN' in flags and len(flags) == 1:
|
||||||
@ -371,7 +371,7 @@ def main():
|
|||||||
'(ports:{0}, interval:{1})'.format(ports,
|
'(ports:{0}, interval:{1})'.format(ports,
|
||||||
args['ival'])
|
args['ival'])
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print (
|
print (
|
||||||
'Salt-Master Network Status '
|
'Salt-Master Network Status '
|
||||||
'(ports:{0}, interval:{1})'.format(ports,
|
'(ports:{0}, interval:{1})'.format(ports,
|
||||||
@ -436,7 +436,7 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user