Re: Sniffer Linux with Raw Socket

Discussion in 'Python' started by Giampaolo Rodolà, Jun 6, 2010.

  1. 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 <>:
    > 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
    >
    >
     
    Giampaolo Rodolà, Jun 6, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. billiejoex

    Sniffer with RAW SOCKETS

    billiejoex, Sep 7, 2005, in forum: Python
    Replies:
    1
    Views:
    425
    Grant Edwards
    Sep 7, 2005
  2. Laszlo Nagy
    Replies:
    1
    Views:
    5,084
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,026
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    594
    Laszlo Nagy
    Feb 1, 2009
  5. Steve Holden
    Replies:
    0
    Views:
    711
    Steve Holden
    Feb 1, 2009
Loading...

Share This Page