#!/usr/bin/env python
from multiprocessing import *
from io import *
import sqlite3
import nmap
import sys
import re
def scanner (s_arg, queue):
nm = nmap.PortScanner ()
nm.scan (host=s_arg, arguments="-n -sS -P 80")
for host in nm.all_hosts ():
for proto in nm[host].all_protocols ():
for port in nm[host][proto].keys ():
if nm[host][proto][port]['state'] == 'open':
queue.put ([host, port])
def updater (queue):
while True:
u_arg = queue.get ()
if ():
{ПОЛЕЗНАЯ_РАБОТА}
else:
break
conn = sqlite3.connect ('proxy.db')
db = conn.cursor ()
networks = []
for row in db.execute ('SELECT network FROM cidr WHERE country <> \'RU\' ORDER BY time ASC LIMIT 5'):
networks.append (row[0])
queue = Queue ()
updater_p = Process (updater, queue)
updater_p.daemon = True
updater_p.start
pool = Pool (5)
pool.map (scanner, [networks, queue])
pool.close ()
pool.join ()
queue.put (END_FLAG)
updater_p.join ()
conn.commit ()
conn.close ()
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgpmcm9tIG11bHRpcHJvY2Vzc2luZyBpbXBvcnQgKgpmcm9tIGlvIGltcG9ydCAqCgppbXBvcnQgc3FsaXRlMwppbXBvcnQgbm1hcAppbXBvcnQgc3lzIAppbXBvcnQgcmUKCmRlZiBzY2FubmVyIChzX2FyZywgcXVldWUpOgogICAgbm0gPSBubWFwLlBvcnRTY2FubmVyICgpCiAgICBubS5zY2FuIChob3N0PXNfYXJnLCBhcmd1bWVudHM9Ii1uIC1zUyAtUCA4MCIpCiAgICBmb3IgaG9zdCBpbiBubS5hbGxfaG9zdHMgKCk6IAogICAgICAgIGZvciBwcm90byBpbiBubVtob3N0XS5hbGxfcHJvdG9jb2xzICgpOiAKICAgICAgICAgICAgZm9yIHBvcnQgaW4gbm1baG9zdF1bcHJvdG9dLmtleXMgKCk6IAogICAgICAgICAgICAgICAgaWYgbm1baG9zdF1bcHJvdG9dW3BvcnRdWydzdGF0ZSddID09ICdvcGVuJzoKICAgICAgICAgICAgICAgICAgICBxdWV1ZS5wdXQgKFtob3N0LCBwb3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