from scapy.all import * pkt = IP(dst="192.168.1.1")/TCP(sport=1234, dport=80, flags="S") send(pkt)
from scapy.all import * target = "192.168.1.1" ports = [80, 443, 8080] for port in ports: pkt = IP(dst=target)/TCP(dport=port, flags="S") resp = sr1(pkt, timeout=2) if resp and resp.haslayer(TCP) and resp.getlayer(TCP).flags == "SA": print(f"Port {port} is open")In this example, we send SYN packets to a list of ports and check if we receive a SYN-ACK response. If we do, the port is considered open. Overall, the `scapy.all` module is a powerful tool for working with TCP packets in Python.