Packet sniffing in Python (Windows)

前端 未结 6 1382
悲&欢浪女
悲&欢浪女 2020-12-01 03:02

What is the best way to sniff network packets using Python?

I\'ve heard from several places that the best module for this is a module called Scapy, unfortunately, it

6条回答
  •  既然无缘
    2020-12-01 03:45

    you can use raw sockets, with your interface ip address (in admin mode),

    import socket
    s = socket.socket(socket.AF_INET,socket.SOCK_RAW,socket.IPPROTO_IP)
    s.bind(("YOUR_INTERFACE_IP",0))
    s.setsockopt(socket.IPPROTO_IP,socket.IP_HDRINCL,1)
    s.ioctl(socket.SIO_RCVALL,socket.RCVALL_ON)
    while True:
       data = s.recvfrom(10000)
       print data
    

提交回复
热议问题