import socket
import multiprocessing
from multiprocessing import Manage, Queue
def scan_port(hostlist, linux_host_queue, no_linux_host_queue):
c_sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
c_sk.connect((addr, 22))
linux_host_queue.put(addr)
except Exception as e
no_linux_host_queue.put(addr)
if __name__ == '__main__':
po = multiprocessing.Pool(30)
m = Manager()
linux_host_queue = m.Queue()
no_linux_host_queue = m.Queue()
linux_host_list = []
no_linux_host_list = []
for host in hostlist:
po.apply_async(scan_port, (host, linux_host_queue, no_linux_host_queue,))
po.close()
po.join()
while not linux_host_queue.empty():
linux_host_list.append(linux_host_queue.get())
while not no_linux_host_queue.empty():
no_linux_host_list.append(linux_host_queue.get())
print(linux_host_list)
print(no_linux_host_list)
最近在做主机扫描的工作,对22端口做初步扫描