Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 54 lines (43 sloc) 1.316 kb
21e416e @dripton Initial commit of some small utility programs.
authored
1 #!/usr/bin/env python
2
3 """Hunting for the TrendNet print server"""
4
5 import socket
6 import threading
7 import Queue
8
9 socket.setdefaulttimeout(5)
10
11 port = 631
12 num_threads = 250
13
14 class ConnectThread(threading.Thread):
15 def __init__(self, in_queue, out_queue):
16 threading.Thread.__init__(self)
17 self.in_queue = in_queue
18 self.out_queue = out_queue
19 self.setDaemon(True)
20
21 def run(self):
22 while True:
23 ip = self.in_queue.get()
24 try:
25 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26 sock.connect((ip, port))
27 except socket.error:
28 self.out_queue.put((ip, False))
29 else:
30 self.out_queue.put((ip, True))
31 self.in_queue.task_done()
32
33 def main():
34 job_queue = Queue.Queue()
35 result_queue = Queue.Queue()
36 count = 0
37 for net in range(1, 255+1):
38 for addr in range(1, 255 + 1):
39 ip = "10.2.%d.%d" % (net, addr)
40 count += 1
41 job_queue.put(ip)
42 for unused in xrange(num_threads):
43 ConnectThread(job_queue, result_queue).start()
44 job_queue.join()
45
46 for unused in xrange(count):
47 ip, status = result_queue.get()
48 if status:
49 print ip
50
51
52 if __name__ == "__main__":
53 main()
Something went wrong with that request. Please try again.