fork(1) download
  1. #!/usr/bin/env python
  2.  
  3. from multiprocessing import *
  4.  
  5. import sqlite3
  6. import nmap
  7. import time
  8.  
  9. def scanner (s_arg):
  10. nm = nmap.PortScanner ()
  11. nm.scan (hosts=s_arg, arguments="-n -sS -T4 -p 80,81,1080,1081,3128,8080,8081")
  12. for host in nm.all_hosts ():
  13. for proto in nm[host].all_protocols ():
  14. for port in nm[host][proto].keys ():
  15. if nm[host][proto][port]['state'] == 'open':
  16. queue.put ([host, port])
  17.  
  18. def updater (db):
  19. while True:
  20. u_arg = queue.get ()
  21. if u_arg:
  22. db.execute ('INSERT INTO open VALUES (?,?,?)', (u_arg[0], u_arg[1], int(time.time())))
  23. else:
  24. break
  25.  
  26. sqlite3.enable_callback_tracebacks (True)
  27. conn = sqlite3.connect ('proxy.db')
  28. db = conn.cursor ()
  29.  
  30. networks = []
  31. for row in db.execute ('SELECT network FROM cidr WHERE country in (\'CN\')'):
  32. networks.append (row[0])
  33.  
  34. queue = Queue ()
  35.  
  36. updater_p = Process (target = updater, args=(db))
  37. updater_p.daemon = True
  38. updater_p.start ()
  39.  
  40. pool = Pool (5)
  41. pool.map (scanner, networks)
  42. pool.close ()
  43. pool.join ()
  44.  
  45. queue.put ([])
  46. updater_p.join ()
  47.  
  48. conn.commit ()
  49. conn.close ()
  50.  
Runtime error #stdin #stdout #stderr 0.03s 10472KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 6, in <module>
ImportError: No module named nmap