def mac_addr(address):
"""Convert a MAC address to a readable/printable string
Args:
address (str): a MAC address in hex form (e.g. '\x01\x02\x03\x04\x05\x06')
Returns:
str: Printable/readable MAC address
"""
return ':'.join('%02x' % ord(b) for b in address)
def inet_to_str(inet):
"""Convert inet object to a string
Args:
inet (inet struct): inet network address
Returns:
str: Printable/readable IP address
"""
# First try ipv4 and then ipv6
try:
return socket.inet_ntop(socket.AF_INET, inet)
except ValueError:
return socket.inet_ntop(socket.AF_INET6, inet)
filename = "/root/python-code/test.pcap"
f = open(filename)
pcap = dpkt.pcap.Reader(f)
for timestamp,buf in pcap:
d = datetime.datetime.fromtimestamp(timestamp)
print 'Time: ',d.strftime("%Y-%m-%d %H:%M:%S.%f")