from scapy.layers.inet import IP, Ether, TCP from scapy.packet import Raw def generate_ip_packet(ip_src="192.168.64.32", ip_dst="192.168.64.48", mac_src="56:6D:D9:BC:70:1C", mac_dst="F4:2B:95:B3:0E:1A", port_src=1337, port_dst=6442, tcpflags="S", payload = ""): ether = Ether(src=mac_src, dst=mac_dst) ip = IP(src=ip_src, dst=ip_dst) tcp = TCP(sport=port_src, dport=port_dst, flags=tcpflags) packet = ether / ip / tcp / Raw(load=payload) return packet