使用Python进行端口扫描
没什么好说的,看代码就行。
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 7 12:10:55 2018
@author: peter
"""
import socket
def Get_ip(domain):
try:
return socket.gethostbyname(domain)
except Exception as e:
print('%s: %s' % (domain, e))
exit()
def PortScan(ip):
print("it will take a long time")
result_list = []
port_list = range(1, 65535)
for port in port_list:
try:
s = socket.socket()
s.settimeout(0.1)
s.connect((ip, port))
openstr = "PORT:"+str(port) + " OPEN "
print(openstr)
result_list.append(port)
s.close()
except:
pass
print(result_list)
def main():
domain = input("PLEASE INPUT YOUR TARGET:")
ip = Get_ip(domain)
print('IP:'+ip)
PortScan(ip)
if __name__ == '__main__':
main()
文档信息
- 本文作者:last2win
- 本文链接:https://last2win.com/2018/04/07/port-scan/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)