1.[文件]
tcp.py ~ 2KB
下载(69)
# -*- coding: cp936 -*-
import socket
from struct import *
from time import ctime,sleep
from os import system
system("title tcp sniffer")
system("color 05")
# the public network interface
HOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))
# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packages
#s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
# receive a package
while 1==1:
packet = s.recvfrom(65565)
packet = packet[0]
ip_header = packet[0:20]
iph = unpack("!BBHHHBBH4s4s",ip_header)
version = iph[0] >> 4 #Version