我试图为实践创建第2层protocole。有我的导入(在两个文件中):
from pystack.layers.ethernet import EthernetProtocol
from pystack.layers.arp import ARPProtocol
from pystack.layers.ethernet import Ether
from scapytrame import EtherData
from scapy.all import *
当我在文件中执行这些行(Sender.py)
时,它非常有效ethData = EtherData(src="00:21:70:a2:b7:6d", dst="d4:3d:7e:6c:66:e9", data="Kikouuu!", seq_ack=9)
sendp(ethData)
print ethData.show()
所以我收到了数据包,我可以在WireShark中看到它 但现在我想通过使用一个函数来做到这一点并不起作用。有第二个文件:
def sender(frames, macSrc="00:21:70:a2:b7:6d", iface="eth0") :
i = 0
sentBack = False
while(i < len(frames)):
# Sending packet
frames[i].seq_ack = hex(i%2);
frames[i].show()
Scapy.sendp(frames[i])
# Acknowledge + Next packet
macDst = frames[i].dst
filtre = "ether src " + macDst
ack = sniff(iface=str(iface), filter=str(filtre), count=1, timeout=5)
if not ack:
sentBack = True
continue
ackData = EtherData(str(ack[0]))
if int(ackData.seq_ack) == 2:
sentBack = False
i = i + 1
else:
continue
def receiver(macSrc="00:21:70:a2:b7:6d", iface="eth0") :
nextFrame = 0
while(True):
ack = sniff(iface=str(iface), filter=str(filtre), count=1)
ackData = EtherData(str(ack[0]))
if int(ackData.seq_ack) == nextFrame%2:
ackData.show()
sender([EtherData(src="00:21:70:a2:b7:6d", dst=ackData.dst, seq_ack=2)])
nextFrame = nextFrame + 1
frames_test = [ EtherData(src="00:21:70:a2:b7:6d", dst="d4:3d:7e:6c:66:e9", data="Kikouuu!", seq_ack=9),
EtherData(src="00:21:70:a2:b7:6d", dst="d4:3d:7e:6c:66:e9", data="Kikouuu!", seq_ack=9),
EtherData(src="00:21:70:a2:b7:6d", dst="d4:3d:7e:6c:66:e9", data="Kikouuu!", seq_ack=9),
EtherData(src="00:21:70:a2:b7:6d", dst="d4:3d:7e:6c:66:e9", data="Kikouuu!", seq_ack=9),
EtherData(src="00:21:70:a2:b7:6d", dst="d4:3d:7e:6c:66:e9", data="Kikouuu!", seq_ack=9)]
sender(frames_test)
然后我收到错误:
Traceback (most recent call last):
File "ProtAckPosAndTrans.py", line 47, in <module>
sender(frames_test)
File "ProtAckPosAndTrans.py", line 15, in sender
sendp(frames[i])
File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 259, in sendp
__gen_send(conf.L2socket(iface=iface, *args, **kargs), x, inter=inter, loop=loop, count=count, verbose=verbose, realtime=realtime)
File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 234, in __gen_send
s.send(p)
File "/usr/lib/python2.7/dist-packages/scapy/supersocket.py", line 32, in send
sx = str(x)
File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 261, in __str__
return self.build()
File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 319, in build
p = self.do_build()
File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 308, in do_build
pkt = self.self_build()
File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 299, in self_build
p = f.addfield(self, p, val)
File "/usr/lib/python2.7/dist-packages/scapy/fields.py", line 70, in addfield
return s+struct.pack(self.fmt, self.i2m(pkt,val))
struct.error: cannot convert argument to integer
帧[i] .show()完美运行,我也做了一个&#39;打印帧[i]。类&#39;一切都找到了...所以我无法理解为什么它不起作用。
我到处搜索都无法找到一个anwser。谢谢你的回答:)