forked from seclab-ucr/INTANG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
32 lines (21 loc) · 737 Bytes
/
tools.py
File metadata and controls
32 lines (21 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from socket import ntohs, inet_ntoa, inet_aton
import struct
def cut(s, l):
if len(s) > l:
return s[:l] + "..."
else:
return s
def ip2str(i):
return inet_ntoa(struct.pack('I', i))
def str2ip(s):
return struct.unpack('I', inet_aton(s))[0]
def print_4tuple(s):
parts = s.split('_')
assert len(parts) == 4, "wrong format"
sip, sport, dip, dport = [int(x) for x in s.split('_')]
print("%s:%d -> %s:%d" % (ip2str(sip), ntohs(sport), ip2str(dip), ntohs(dport)))
def parse_4tuple(s):
parts = s.split('_')
assert len(parts) == 4, "wrong format"
sip, sport, dip, dport = [int(x) for x in s.split('_')]
return ip2str(sip), ntohs(sport), ip2str(dip), ntohs(dport)