0

I'm trying to implement a threading functionality for this answer : Scanning a Class C network Python

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 !

Community
  • 1
  • 1
nabs1
  • 43
  • 1
  • 4
  • 1
    This example http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/ mixes threading and network stuff. It might provide ideas. – Nick T Aug 25 '10 at 03:07

3 Answers3

1

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
  • 11
  • 1
0

I once wrote a multi-threaded port scanner. Feel free to use it for some ideas on improving performance. Over time, it has been improved and refactored such that it doesn't provide a concise example, but instead implements a more robust implementation with re-usable components. I hope the core ideas aren't masked by the abstraction.

Jason R. Coombs
  • 41,115
  • 10
  • 83
  • 93
-1

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
  • 12,561
  • 6
  • 44
  • 51
  • 1
    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 Aug 25 '10 at 03:28