Python与libpcap. 查找数据包的源MAC地址
我正在写一个Python程序,用来通过pcap构建MAC地址缓存。不过,Python的pcap模块没有很好的文档。我找到这个页面 http://pylibpcap.sourceforge.net/,上面有代码示例,运行得很好。
有没有人能修改这个示例,让它能显示每个数据包的源MAC地址?或者指引我去哪里可以找到相关的文档让我阅读……
更新
这里是代码的一部分,关于MAC地址的信息被删掉了。
def print_packet(pktlen, data, timestamp):
if not data:
return
if data[12:14]=='\x08\x00':
decoded=decode_ip_packet(data[14:])
print '\n%s.%f %s > %s' % (time.strftime('%H:%M',
time.localtime(timestamp)),
timestamp % 60,
decoded['source_address'],
decoded['destination_address'])
for key in ['version', 'header_len', 'tos', 'total_len', 'id',
'flags', 'fragment_offset', 'ttl']:
print ' %s: %d' % (key, decoded[key])
print ' protocol: %s' % protocols[decoded['protocol']]
print ' header checksum: %d' % decoded['checksum']
print ' data:'
dumphex(decoded['data'])
数据的前14个字节是目的地、源MAC地址和以太网类型。
decoded=decode_ip_packet(data[14:])
我需要解析这些信息来获取这些数据。任务完成。