Python Forum
creating new layer with scapy - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: creating new layer with scapy (/thread-5137.html)



creating new layer with scapy - omerccohen - Sep-20-2017

hi i tried to create a new layer in scapy but when i send the packet to another computer and ask to print it ,y new layer got lost the class of the new layer appers in both computers on first i wrote creating and sending packets functions and on the another i wrote sniff function. here is the code on the sending computer



import sys
i, o, e = sys.stdin, sys.stdout, sys.stderr
from scapy.all import *
sys.stdin, sys.stdout, sys.stderr = i, o, e
from scapy.packet import *
from scapy.fields import *
from scapy.layers.inet import UDP, IP
from scapy.layers.dns import DNS
from scapy.layers.l2 import Ether

vxlanmagic = "0x8"


class Vxlan(Packet):
name = "Virtual eXtensible Local Area Network"
fields_desc = [ByteField("flag", 8),
X3BytesField("reserved1", 0),
X3BytesField("vni", 0),
ByteField("reserved2", 0)]

def guess_payload_class(self, payload):
if self.flag == vxlanmagic:
return Vxlan
else:
return Packet.guess_payload_class(self, payload)

def mysummary(self):
return self.sprintf("VXLAN (vni=%VXLAN.vni%)")

split_layers(UDP, DNS, sport=53)
bind_layers(UDP, Vxlan, dport=4789)
bind_layers(Vxlan, Ether)
packet = IP(dst='192.168.1.28')/Vxlan()
packet.show()
send(packet)