#!/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)
- 本文固定链接: https://www.gayj.cn/?p=670
- 转载请注明: https://www.gayj.cn/