def IP_layer(attributes): layer3 = IP() layer3.version = attributes['version'] layer3.ihl = attributes['ihl'] layer3.tos = attributes['tos'] layer3.len = attributes['len'] layer3.id = attributes['id'] layer3.flags = attributes['flags'] layer3.frag = attributes['frag'] layer3.ttl = attributes['ttl'] layer3.proto = attributes['proto'] layer3.src = attributes['src'] layer3.dst = attributes['dst'] return layer3
index = 0 ip_source = [0, 0, 0, 0] ip_source[index] = "" for i in ip_src: if i.isdigit(): ip_source[index] = str(ip_source[index]) + str(i) else: index += 1 ip_source[index] = "" print(ip_source) print(ip_dest) ip_header.version = 4 ip_header.ihl = ip_hdr_len // 4 ip_header.tos = 0x0 ip_header.len = (ip_hdr_len + udp_pkt_len) ip_header.id = 0 ip_header.flags = 0 ip_header.frag = 0 ip_header.ttl = 64 ip_header.proto = 17 #ip_header.chksum= 0x7ce6 ip_header.src = ip_src ip_header.dst = ip_dst del ip_header.chksum ip_header = ip_header.__class__(str(ip_header)) #ip_header.show2() #print("-------------------------------------")
#!/usr/bin/python from scapy.all import IP, TCP a = IP() a.src = "1.2.3.4" a.dst = "10.0.2.15" a.ihl = 5 b = TCP() b.sport = 1551 b.dport = 23 b.seq = 1551 b.flags = 'S' pkt = a/b with open("packet", "wb") as f: f.write(bytes(pkt))