@@ -0,0 +1,919 @@
+from socket import *%0A%0ArawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)%0ArawSocket.bind(('wlan0', 0))%0A%0Awhile True:%0A%0A    data = rawSocket.recv(2048)%0A%0A    # http://en.wikipedia.org/wiki/IPv4#Packet_structure%0A%0A    # Internet Header Length; Have to determine where the IP header ends%0A    ihl = ord(data%5B0%5D) & 15%0A    ip_payload = data%5Bihl*4:%5D%0A%0A    # http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure%0A%0A    # Match SYN but not SYN/ACK%0A    if (ord(ip_payload%5B13%5D) & 18) == 2:%0A        src_addr = inet_ntoa(data%5B12:16%5D)%0A        dst_addr = inet_ntoa(data%5B16:20%5D)%0A%0A        # Could use struct.unpack, might be clearer%0A        src_port = (ord(ip_payload%5B0%5D) %3C%3C 8) + ord(ip_payload%5B1%5D)%0A        dst_port = (ord(ip_payload%5B2%5D) %3C%3C 8) + ord(ip_payload%5B3%5D)%0A%0A        src_str = (src_addr+':'+str(src_port)).ljust(22)%0A        dst_str = (dst_addr+':'+str(dst_port))%0A%0A        print %22%25s=%3E %25s%22 %25 (src_str, dst_str)%0A

Create monitor_tcp_ports.py