views:

36

answers:

2

Hi Alls,

I'm trying to implement a threading functionality for this answer : http://stackoverflow.com/questions/3491727/scanning-a-class-c-network-python/3492399#3492399

So far i have something like this:

...[snip]..
m = re.search("/", str(host))
if m :
   net,_,mask = host.partition('/')
   mask = int(mask)
   net = atod(net)
   for host in (dtoa(net+n) for n in range(0, 1<<32-mask)):
      try:
         mycustomsocket(host)
      except:
         print host+" is down"
         pass
else:
   mycustomsocket(host)

What I'm looking for, would be to open 255 thread to scan all hosts parsed with mycustomsocket() at once, for speed issues.

Any help would be greatly appreciated !

A: 

This question is not very specific. It sounds like: "I need threading support for my code, please do the work for me."

Please read the docs about threading in Python and related topics like the Queue class. If you have a more specifc question, come back and ask again.

leoluk
No I simply want to know how should i do that.I'm a beginner, and I have the right to don't know something, OK.
nabs1
+1  A: 

I think he did give you the answer, go and read the docs and then come back when you have specific questions on implementing the threading code... If you read the article on devshed already mentioned you can see how you create your own thread class and pass the ip address you want to work with into the thread and put your working code there with some sort of threadsafe queue where the thread can put back whatever information you are after.

ckrracing