2017-08-04 28 views
1

我的包:IPOptions在scapy3.0.0和python3.5拋出錯誤

a=IP(src="30.1.1.2",dst="20.1.1.2",options=IPOption('\x83\x07\x04\x00\x00\x00\x00\x00'),) 

我收到錯誤:

a=bytes(IP(src="30.1.1.2",dst="20.1.1.2",options=IPOption('\‌​x83\x07\x04\x00\x00\‌​x00\x00\x00'),)) 
Traceback (most recent call last): 
    File "/usr/lib/python3.4/code.py", line 90, in runcode exec(code, self.locals) 
    File "<console>", line 1, in <module> 
    File "/usr/local/lib/python3.4/dist-packages/scapy/base_classes.p‌​y", line 197, in call 
    cls = cls.dispatch_hook(*args, **kargs) 
    File "/usr/local/lib/python3.4/dist-packages/scapy/layers/inet.py‌​", line 161, in dispatch_hook 
    opt = pkt[0] & 0x1f 
TypeError: unsupported operand type(s) for &: 'str' and 'int' – 
+0

錯誤>>> a = bytes(IP(src =「30.1.1.2」,dst =「20.1.1.2」,options = IPOption('\ x83 \ x07 \ x04 \ x00 \ x00 \ x00 \ x00 \ x00'))) Traceback (最新最後調用): 文件 「/usr/lib/python3.4/code.py」,行90,在runco​​de EXEC(代碼self.locals) 文件 「」,1號線,在 文件「/usr/local/lib/python3.4/dist-packages/scapy/base_classes.py」,第197行,在__call__中 cls = cls.dispatch_hook(* args,** kargs) 文件「/ usr/local /lib/python3.4/dist-packages/scapy/layers/inet.py「,第161行,在dispatch_hook中 opt = pkt [0]&0x1f TypeError:不支持的操作數類型爲&:'str'和'int' – Muralidhar

回答

1

既然你使用Python 3,你應該使用bytes而不是str作爲IP選項:

a = bytes(IP(src="30.1.1.2", dst="20.1.1.2", 
      options=IPOption(b'\x83\x07\x04\x00\x00\x00\x00\x00')) 
+0

a = IP(src =「30.1.1.2」,dst =「20.1.1.2」, options = IPOption(b'\ x83 \ x07 \ x04 \ x00 \ x00 \ x00 \ x00 \ x00')。我相信不需要將整個IP數據包轉換爲字節。只是將IPOption轉換爲字節幫助了我。謝謝皮埃爾。 – Muralidhar

+0

我剛剛修復了最後一行,它以'a = bytes(IP([...]))'開始。當然,如果你想創建一個IP Scapy包,不需要'bytes()'。但是如果你想創建將要在網絡上發送的字節,你需要它。 – Pierre