python 端口扫描

# coding: utf-8
import socket
from datetime import datetime
from multiprocessing.dummy import Pool as ThreadPool

remote_server = input("Enter a remote host to scan:")#
remote_server_ip = socket.gethostbyname(remote_server)
ports = []

print ('-' * 60)
print ('Please wait, scanning remote host ', remote_server_ip)
print ('-' * 60)


socket.setdefaulttimeout(0.5)

def scan_port(port):
try:
s = socket.socket(2,1)
res = s.connect_ex((remote_server_ip,port))
if res == 0: # 如果端口开启 发送 hello 获取banner
print ('Port {}: OPEN'.format(port))
s.close()
except Exception as e:
print (str(e.message))

for i in range(1,1025):
ports.append(i)

# Check what time the scan started
t1 = datetime.now()


pool = ThreadPool(processes = 8)
results = pool.map(scan_port,ports)
pool.close()
pool.join()

print ('Multiprocess Scanning Completed in ', datetime.now() - t1)

  

转载于:https://www.cnblogs.com/muxueyuan/p/8483510.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值