39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
@Time : 2023/08/30
|
|
@Author : Carol
|
|
@Site :
|
|
@File : ipv4.py
|
|
@Software: PyCharm
|
|
@Description: 扫描全部端口并返回对外暴露的端口号集合
|
|
- 1- 1024 固定类别端口
|
|
- 1025- 65535 自定义端口
|
|
"""
|
|
import socket
|
|
|
|
|
|
def __port_checker(ip_address_or_domain, port_number):
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
try:
|
|
sock.connect((str(ip_address_or_domain), int(port_number)))
|
|
print("PORT {0} is OPEN on '{1}'.".format(port_number, ip_address_or_domain))
|
|
return port_number
|
|
except Exception as e:
|
|
print("PORT {0} is CLOSED on '{1}', exception: {2}.".format(port_number, ip_address_or_domain, str(e)))
|
|
return None
|
|
finally:
|
|
sock.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
domain = "redirect.cnkj.site"
|
|
ports = []
|
|
for i in range(1, 65535):
|
|
port = __port_checker(domain, i)
|
|
if None is not port:
|
|
ports.append(port)
|
|
print("当前 {0} 域名对外开放的端口合集: \n".format(domain))
|
|
for p in ports:
|
|
print(p)
|