fork download
  1. #!/usr/bin/env python
  2.  
  3. from multiprocessing import *
  4. from io import *
  5.  
  6. import sqlite3
  7. import nmap
  8. import sys
  9. import re
  10.  
  11. def scanner (s_arg, queue):
  12. nm = nmap.PortScanner ()
  13. nm.scan (host=s_arg, arguments="-n -sS -P 80")
  14. for host in nm.all_hosts ():
  15. for proto in nm[host].all_protocols ():
  16. for port in nm[host][proto].keys ():
  17. if nm[host][proto][port]['state'] == 'open':
  18. queue.put ([host, port])
  19.  
  20. def updater (queue):
  21. while True:
  22. u_arg = queue.get ()
  23. if ():
  24. {ПОЛЕЗНАЯ_РАБОТА}
  25. else:
  26. break
  27.  
  28. conn = sqlite3.connect ('proxy.db')
  29. db = conn.cursor ()
  30.  
  31. networks = []
  32. for row in db.execute ('SELECT network FROM cidr WHERE country <> \'RU\' ORDER BY time ASC LIMIT 5'):
  33. networks.append (row[0])
  34.  
  35. queue = Queue ()
  36. updater_p = Process (updater, queue)
  37. updater_p.daemon = True
  38. updater_p.start
  39.  
  40. pool = Pool (5)
  41. pool.map (scanner, [networks, queue])
  42. pool.close ()
  43. pool.join ()
  44.  
  45. queue.put (END_FLAG)
  46. updater_p.join ()
  47.  
  48. conn.commit ()
  49. conn.close ()
Runtime error #stdin #stdout #stderr 0.08s 11672KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 7, in <module>
ImportError: No module named 'nmap'