Cualquier pregunta o duda, no duden en postearla.
PsData: Fue probado en Linux, se necesitan privilegios para ejecutar.
Código
#! /usr/bin/env python ######################################################################## #Script : WhoPingMe.py # #Description: Detect if you receive a Ping and make a list with Date. # #By : LordRNA # #Date` : Sept 19th-2010 # #Comments : Tested on Python 2.6.5 # ######################################################################## import socket, datetime def whopingme(date): source = '' #To put the IP Source. header = ["%i"%ord(x) for x in data] #I made a list of int values for each byte in data variable. if int(header[20])==8:#If Type(ICMP) is 8, i received a Echo Request. for x in range(4):#To make a string with the IP Source. source += str(header[12+x]) if x<3:source +='.' date = str(datetime.datetime.today()) print date[:len(date)-7]+" ---> "+ str(source) #I deleted the Miliseconds with [:len(date)-7] sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP) #ICMP Protocol on RAW Socket while 1: data = sock.recv(21)#I Just want these bytes, IPHeader Lenght + Type(ICMPHeader) whopingme(data)#Sending data to whopingme() function.
Muestra de la Salida del programa:
Código:
rna@rna-laptop:~$ sudo python ./whopingme.py
2010-09-19 00:47:57 ---> 192.168.10.230
2010-09-19 00:47:58 ---> 192.168.10.230
2010-09-19 00:47:59 ---> 192.168.10.230
Edito: Segun me ha dicho Karcrack, LittleHorse y ctlon deberia funcionar en windows con privilegios de administrador.