一个简单的客户端 - 服务器原始套接字,客户端发送自定义数据包,然后从服务器接收。
这是我的代码。
Client.py
#!/usr/bin/env python
import socket
import sys
from scapy.all import *
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
try:
a=Ether(dst="90:**:**:**:**:75", src="90:**:**:**:**:96")/IP(src="192.168.240.5", dst="192.168.240.1")/TCP(sport=10000,dport=10000)/"HELLO"
a.show()
sendp(a)
finally:
print >>sys.stderr, 'closing socket'
sock.close()
输出:
###[ Ethernet ]###
dst = 90:**:**:**:**:75
src = 90:**:**:**:**:96
type = 0x800
###[ IP ]###
version = 4
ihl = None
tos = 0x0
len = None
id = 1
flags =
frag = 0
ttl = 64
proto = tcp
chksum = None
src = 192.168.240.5
dst = 192.168.240.1
\options \
###[ TCP ]###
sport = 10000
dport = 10000
seq = 0
ack = 0
dataofs = None
reserved = 0
flags = S
window = 8192
chksum = None
urgptr = 0
options = {}
###[ Raw ]###
load = 'HELLO'
.
Sent 1 packets.
closing socket
Server.py
#!/usr/bin/env python
import socket
import sys
from scapy.all import *
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
sock.bind(("wlan0",10000))
def pkt_callback(pkt):
pkt.show() # debug statement
while True:
print >>sys.stderr, 'waiting for a connection'
sniff(iface="wlan0", prn=pkt_callback, store=0)
服务器向我显示它拦截的每个数据包,但没有client.py脚本发送的数据包的迹象。我猜它根本就没发送过。
有什么问题?