Python_sniffer (Network Sniffer)

Source: Internet
Author: User

ImportSocketImportThreadingImportTimeactivedegree=dict () flag=1defMain ():GlobalActivedegreeGlobalGlag#get the native IP addresshost=Socket.gethostbyname (Socket.gethostbyname ())#create raw sockets for Windows platforms    #for other systems, the socket is to be put. Ipproto_ip replaced by socket.ipproto_icmps=Socket.socket (Socket.af_inet,socket. Sock_raw,socket. IPPROTO_IP) S.bind ((host,0) )#set the IP header to be included in the capture packetS.setsockopt (socket. Ipproto_ip,socket. ip_hdrincl,1)    #enable promiscuous mode to capture all packetsS.ioctl (socket. Sio_rcvall,socket. RCVALL_ON)#Start capturing packets     whileFlag:c=s.recvfrom (65535) Host=c[1][0] Activedegree[host]=activedegree.get (host,0) +1#Suppose the native IP address is 10.2.1.8        ifC[1][0]! ='10.2.1.8':            Print(c)#turn off promiscuous modeS.ioctl (socket. Tio_rcvall,socket. Rcvall_off) S.close () T=threading. Thread (target=main) T.start () Time.sleep (60) Flag=0t.join () forIteminchActivedegree.items ():Print(item)

Python_sniffer (Network Sniffer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.