A simple client-server raw socket where the client send a custom packet and it will be received from the server.
Here's my code.
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()
Output:
###[ 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)
The server shows me every packets it intercepts but there's no sign of the one sent by the client.py script. I guess it is not sent at all.
What is the problem?