问题描述
我有2个程序通过以太网相互通信。发送一个是使用scapy对端口,ip和有效负载进行编码,然后再将其作为以太网帧发送。我的问题是,在有效载荷中,我正在发送计数器,并且在接收到它有时会更改为符号时。
\x00\x00\x00\x00\x00\x00\x00\x07
\x00\x00\x00\x00\x00\x00\x00\x08 is fine but next
\x00\x00\x00\x00\x00\x00\x00\t
\x00\x00\x00\x00\x00\x00\x00\n
\x00\x00\x00\x00\x00\x00\x00\x0b its fine again
后来将其更改为下一个asci符号
我的问题是如何停止将字节转换为asci?
sender.py
import socket
from scapy.all import *
PADDING_VALUE = b'\xd1'
ETH_P_ALL = 3
DST_IP = "127.0.0.12"
IFACE = "lo"
SRC_IP = "127.0.0.11"
class FpgaMockup:
def __init__(self,setup_iface):
self.setup_sock = socket.socket(socket.AF_PACKET,socket.SOCK_RAW,socket.htons(ETH_P_ALL))
self.setup_sock.bind((setup_iface,0))
self.padding = 16
def send(self,pkt):
self.setup_sock.send(pkt)
if __name__ == "__main__":
testing_fpga = FpgaMockup(IFACE)
for i in range(100):
packet = IP(dst=DST_IP,src=SRC_IP)/UDP(sport=12666,dport=12666)/Raw(load=int(i).to_bytes(8,"big")+PADDING_VALUE*testing_fpga.padding)
pkt = Ether(packet)
testing_fpga.send(raw(pkt))
print("Finished sending.")
reciever.py
import socket
ETH_P_ALL = 3
s = socket.socket(socket.AF_PACKET,socket.htons(ETH_P_ALL))
s.bind(("lo",0))
while(True):
pkt = s.recv(4096)
print(pkt)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)