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(IPPROTO_IP, IP_HDRINCL, 1)
s.sendto('test', ('127.0.0.1', 0)) # without this it doesn't work.
recv()


.



Relevant Pages

  • asyncores lack of sendto(), recvfrom()
    ... Is there any good reason why sendto() and recvfrom() aren't wrapped by ... Obviously, recvfrom() cannot be replaced by recv, but even ... Now, if I'd want to add sendtoand recvfromto asyncore, would it ...
    (comp.lang.python)
  • Re: Using Connect to specify where packet can come from
    ... once you use connect function for UDP, you don't need to use sendto and ... recvfrom function, instead, you can use sendand recv. ... address info is stored in the memory. ...
    (comp.os.vxworks)