Sniffer with RAW SOCKETS

B

billiejoex

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(,[],[],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()
 
G

Grant Edwards

Hi all. I'm trying to make a simple icmp sniffer by using
SOCK_RAW.

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

'Fraid not.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top