首页 > Script > Python > 端口扫描检查
2019
05-10

端口扫描检查

#!/usr/bin/python
# coding=utf-8

”’
Created on 2017年3月26日
@author: lgq
”’

”’
@网络工具
端口扫描检查
”’

print(‘+’ * 22)
print(“Python—多线程端口扫描检查”)
print(‘+’ * 22)
print(‘ ‘)
import socket
from datetime import datetime

# Set time-out to get the scanning fast
socket.setdefaulttimeout(0.5)

# Ask for input
remote_server = input(“请输入扫描的域名/IP地址:”)
remote_server_ip = socket.gethostbyname(remote_server)

# Print a nice banner with info on which host we are about to scan
print (‘-‘ * 60)
print (‘请稍后, 正在扫描中。。。。。 ‘, remote_server_ip)
print (‘-‘ * 60)

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

# Using the range function to specify ports(1 – 1024)
# We also put in some error handling for catching errors
try:
for port in range(1,1025):
sock = socket.socket(2,1) # 2:socket.AF_INET 1:socket.SOCK_STREAM
sock.settimeout(0.1)
res = sock.connect_ex((remote_server_ip,port))
if res == 0:
print (‘端口 {}: OPEN’.format(port))
sock.close()

except socket.gaierror:
print (‘*主机名无法解析*’)

except socket.error:
print (“*不能连接到服务器*”)

# Check the time now
t2 = datetime.now()

# Calculates the difference of time
total = t2 – t1

# Print the info to screen
print(‘扫描完成耗时: ‘, total)

最后编辑:
作者:李国庆
这个作者貌似有点懒,什么都没有留下。
捐 赠如果您觉得这篇文章有用处,请支持作者!鼓励作者写出更好更多的文章!

留下一个回复

你的email不会被公开。