Sniffer with RAW SOCKETS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • billiejoex

    #1

    Sniffer with RAW SOCKETS

    Hi all. I'm trying to make a simple icmp sniffer by using SOCK_RAW.
    The code below works but ONLY if I first use the sendto() function.
    Does anybody knows why?
    Regards

    from socket import *
    import select
    def recv():
    while 1:
    if s in select.select([s],[],[],99)[0]:
    reply = s.recvfrom(2000 )[0]
    print reply
    s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)
    s.setsockopt(IP PROTO_IP, IP_HDRINCL, 1)
    s.sendto('test' , ('127.0.0.1', 0)) # without this it doesn't work.
    recv()


  • Grant Edwards

    #2
    Re: Sniffer with RAW SOCKETS

    On 2005-09-07, billiejoex <billiejoex@fas twebnet.it> wrote:
    [color=blue]
    > Hi all. I'm trying to make a simple icmp sniffer by using
    > SOCK_RAW.[/color]

    Just a suggestion: you'd probably be better off using the PCAP
    library.
    [color=blue]
    > The code below works but ONLY if I first use the sendto()
    > function. Does anybody knows why?[/color]

    'Fraid not.

    --
    Grant Edwards grante Yow! I just bought
    at FLATBUSH from MICKEY
    visi.com MANTLE!

    Comment

    Working...