我在Python 2.7中使用SCAPY Lib构建IGMP数据包。 并在我的代码中使用hexdump逻辑。但是在执行下面的代码时会出错。
ipPacket=inet.Ether(dst="01:00:5E:00:00:02",src="30:01:02:03:04:05")
/inet.IP(src="0.0.0.0",dst="224.0.0.2")/IGMP(gaddr="225.0.0.1",type=0x17)
length = 16
FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])
lines = []
for c in xrange(0, len(ipPacket), length):
chars = ipPacket[c:c+length]
hex = ' '.join(["%02x" % ord(x) for x in chars])
printable = ''.join(["%s" % ((ord(x) <= 127 and FILTER[ord(x)]) or '.') for x in chars])
lines.append("%04x %-*s %s\n" % (c, length*3, hex, printable))
payload = ''.join(lines)
hex = ' '.join(["%02x" % ord(x) for x in chars])
TypeError: ord() expected string of length 1, but Ether found
如果有人在此之前遇到过这个问题,请告诉我。