这是服务器接受icmp包的代码
import socket
service1=socket.socket(socket.AF_INET,socket.SOCK_RAW)
service1.bind(('127.0.0.1',6))
data,add=quest1.recv(100)
print(data)
运行后报错
为什么呢?
这是icmp包制造的代码
import struct,array
import socket
service=socket.socket(socket.AF_INET,socket.SOCK_RAW)
service.connect(('127.0.0.1,6'))
head=struct.pack('bbHHh',8,0,0,1,1)
data=struct.pack('h',4)
bao=head+data
def jiaoyan(bao):
sum=0
if len(bao)&1:
bao=bao+b'\0'
words=array.array('h',bao)
for word in words:
sum+=word
word=word>>16+word&0xffff
word = word >> 16 + word & 0xffff
return ~sum&0xffff
head=struct.pack('bbHHh',8,0,jiaoyan(bao),1,1)
bao=head+data
service.send(bao)
这又是为什么呢?