diff --git a/.gitignore b/.gitignore index 4e09186..f6c6f52 100644 --- a/.gitignore +++ b/.gitignore @@ -198,3 +198,7 @@ vendor hs_err_pid* replay_pid* +.*/*.iml +.idea/ +python/.idea +shell/.idea diff --git a/README.md b/README.md index 5022c1a..f745d1c 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ ## python * [ipv4_aliyun.py](python%2Fipv4_aliyun.py) 解析动态ipv4到DNS中 +* [port_scan.py](python%2Fport_scan.py) 端口扫描 ## shell diff --git a/python/ipv4_aliyun.py b/python/ipv4_aliyun.py index d405f3b..e72c310 100644 --- a/python/ipv4_aliyun.py +++ b/python/ipv4_aliyun.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """ @Time : 2023/08/23 - @Author : LXW + @Author : Carol @Site : @File : ipv4.py @Software: PyCharm diff --git a/python/port_scan.py b/python/port_scan.py new file mode 100644 index 0000000..87c9c8a --- /dev/null +++ b/python/port_scan.py @@ -0,0 +1,38 @@ +#!/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)