getting quick arp request

seb sebastien.thur at laposte.net
Wed Sep 6 08:03:13 EDT 2006


Hello,

****************
What I need :
****************

I need to write a scanner that test all the IP adresses that repond on
a given port.
The Ip list is of roughly of length 200.
I need to get the response every 60 seconds (or better).

I would prefer first not to use nmap.

****************
Configuration :
*****************
Python 2.4.1.
To test what is going on I use ethereal.
I am using winXP pro on a 2GHZ P4 and 512 Mo.

***********
Problem :
***********

I tried to implement a simplistic threaded version where each thread is
opening a blocking socket on the IP and port.

I have monitored using etherereal that I get one arp query every second
roughly.

I am expecting a speed on the same oder of magnitude as the one that
one can get from a standard IP/port scanner. To compare, I have used
angry Ip scanner and I have seen that roughly 200 arp request where
sent in 20 seconds.

*******
Also :
*******

I have also considered using some asynchrone connection but AFAIK you
need first to open the socket and so to use the arp protocol.


Thanks I advance for your help.

Sebastien.

*****************
Code sample :
*****************

# Sebastien 6/9/2006 for testing purposes

import time
import Queue
from threading import *
import threading
import socket

try :
	import psyco
	psyco.full()
except :
	pass

class socket_test (Thread):
	def __init__ (self,adresse):
		Thread.__init__(self)
		self.PORT=21
		self.adresse=str(adresse)
		print "in thread adresse = ", self.adresse
		self.service=[]
		self.start()

	def run(self) :
		service_unit=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		service_unit.setblocking(1)
		print "socket Ip = ",self.adresse

		try :
			service_unit.connect((str(self.adresse), self.PORT))
		except Exception,e:
			print "exception ",e

		self.service.append(service_unit)



class groupe_thread :

	def __init__(self,liste):
		self.liste=liste

	def go(self):
		print "self.liste = ",self.liste
		for el in self.liste :
			print "go starting thread on : ",el
			s=socket_test(el)




liste=[]
base ="192.168.3."
rang=range(1,50)
for r in rang:
	add=base+str(r)
	liste.append(add)
a=groupe_thread(liste)
ut= a.go()
print "the end (main) .."




More information about the Python-list mailing list