master-thesis/bin/send_udp_packet_v4.py

34 lines
770 B
Python
Raw Normal View History

2019-07-10 12:37:58 +00:00
#!/usr/bin/python3
import sys
from scapy.all import *
2019-07-10 13:11:19 +00:00
import checksum_from_scapy
2019-07-10 12:37:58 +00:00
if __name__ == '__main__':
iface = sys.argv[1]
e = Ether(src="00:00:0a:00:00:03", dst='00:00:0a:00:00:01')
i = IP(src = "10.0.0.1", dst = "10.1.1.1")
u = UDP(dport=80, sport=80)
d = "V4-OK"
2019-07-10 12:47:10 +00:00
v6 = IPv6(src="2001:db8:1::a00:1", dst="2001:db8::1")
2019-07-10 12:37:58 +00:00
pkg = e / i / u / d
2019-07-10 12:47:10 +00:00
pkg_v6 = e / v6 / u / d
2019-07-10 12:40:49 +00:00
packet_rebuild = pkg.__class__(str(pkg))
2019-07-10 12:37:58 +00:00
print("pkg = {}".format(pkg.__repr__()))
2019-07-10 12:40:03 +00:00
print("checksum = {}".format(packet_rebuild[UDP].chksum))
2019-07-10 12:37:58 +00:00
2019-07-10 12:47:10 +00:00
v6_rebuild = pkg_v6.__class__(str(pkg_v6))
print("v6: {} - {}".format(v6_rebuild.__repr__(), v6_rebuild[UDP].chksum))
2019-07-10 13:13:00 +00:00
# checksum_from_scapy.checksum()
2019-07-10 13:11:19 +00:00
2019-07-10 12:47:10 +00:00
2019-07-10 12:37:58 +00:00
sendp(pkg, iface=iface, verbose=True)