0

首先,我使用的是 Windows 7,(我已经读过这可能会导致我的问题),我正在尝试使用 python 发送带有自定义 IP 标头的 RAW IP 数据包,但是当我试图捕捉使用wireshark,我设法捕获了一个数据包,但是数据包看起来像这样,我的Windows内核创建了一个自动IP头并添加了我创建的IP头作为IP有效负载,现在我想了解的是什么我的代码错了吗?我该如何解决它,以便能够发送带有自定义 IP 标头的原始 IP 数据包?这是我的代码:

import socket
import struct

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)



ipheader = ''

byte1 = int(bin(4)[2:].zfill(4)+bin(5)[2:].zfill(4),2)

ipheader = ipheader + struct.pack('!B',byte1)

byte2 = 0

ipheader = ipheader + struct.pack('!B',byte2)

byte34 = 0

ipheader = ipheader + struct.pack('!H',byte34)

byte56 = 16

ipheader = ipheader + struct.pack('!H',byte56)

byte78 = 0

ipheader = ipheader + struct.pack('!H',byte78)

byte9 = 50 

ipheader = ipheader + struct.pack('!B',byte9)

byte10 = 6

ipheader = ipheader + struct.pack('!B',byte10)

byte1112 = 0 

ipheader = ipheader + struct.pack('!H',byte1112)

byte13 = 10
byte14 = 0
byte15 = 0
byte16 = 1

ipheader = ipheader + struct.pack('!4B',byte13,byte14,byte15,byte16)

byte17 = 8
byte18 = 8
byte19 = 8
byte20 = 8

ipheader = ipheader + struct.pack('!4B',byte17,byte18,byte19,byte20)

s.sendto(ipheader,("8.8.8.8",0))

print len(ipheader)

提前致谢。

4

0 回答 0