I am trying to send a custom packet (with a custom layer) using Scapy in python socket.
Here's the code of the client
#!/usr/bin/env python
import socket
from scapy.all import *
TCP_PORT = 5000
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.240.1', TCP_PORT))
class Reservation(Packet):
name = "ReservationPacket"
fields_desc=[ ByteField("id", 0),
BitField("type",None, 0),
X3BytesField("update", 0),
ByteField("rssiap", 0)]
k = IP(dst="192.168.240.1")/Reservation()
k.show()
send(k)
print "Reservation Message Sent"
s.close()
and the packet k appears to be successfully created and sent.
Here's the server which is responsible to receive the packet:
#!/usr/bin/python
import socket
from scapy.all import *
class Reservation(Packet):
name = "ReservationPacket"
fields_desc=[ ByteField("id", 0),
BitField("type",None, 0),
X3BytesField("update", 0),
ByteField("rssiap", 0)]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('192.168.240.1', 5000))
s.listen(1)
while True :
conn, addr = s.accept()
print 'Connection address:', addr
print ''
data = conn.recv(1024)
data.show()
conn.close
s.close()
and this is the output I get from the server:
Connection address: ('192.168.240.5', 58454)
Traceback (most recent call last):
File "server.py", line 36, in <module>
data.show()
AttributeError: 'str' object has no attribute 'show'
How can I receive my packet and decode it to read its custom layer?