Python 2.7:TypeError:ord()期望的长度为1的字符串,但是找到了Ether

时间:2017-11-23 11:03:28

标签: python scapy

我在Python 2.7中使用SCAPY Lib构建IGMP数据包。 并在我的代码中使用hexdump逻辑。但是在执行下面的代码时会出错。

构建scapy IGMP数据包

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) 

hexdump logic

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

如果有人在此之前遇到过这个问题,请告诉我。

0 个答案:

没有答案