From: Giampaolo RodolĂ  on
RAW sockets are not recommended for doing such kind of things.
It is a lot easier and portable using libpcap.
Python has a lot of libpcap bindings you can use (pcapy, pypcap, etc...).
Just google for it.


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil

2010/6/6 castor91 <castor91(a)gmail.com>:
> Hi all, i try to make a python sniffer for linux using raw socket and not
> pcap or scapy.. But i have a lot of problems..
> I use the code that i found here:
> http://docs.python.org/library/socket.html
>
> import socket
>
> # 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
> print s.recvfrom(65565)
>
> # disabled promiscuous mode
> s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
>
> but the attribute "ioctl" is only for windows platform... and also i must
> replace "socket.IPPROTO_IP" with "9" because it doesn't work ( i found the
> answer in a web topic)
> How do i ???
> Thanks and sorry for bad english.
> --castor91
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>