add: port_scan.py
This commit is contained in:
parent
644c99b3da
commit
d7dd8d24c4
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -198,3 +198,7 @@ vendor
|
|||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
.*/*.iml
|
||||
.idea/
|
||||
python/.idea
|
||||
shell/.idea
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
## python
|
||||
|
||||
* [ipv4_aliyun.py](python%2Fipv4_aliyun.py) 解析动态ipv4到DNS中
|
||||
* [port_scan.py](python%2Fport_scan.py) 端口扫描
|
||||
|
||||
## shell
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/08/23
|
||||
@Author : LXW
|
||||
@Author : Carol
|
||||
@Site :
|
||||
@File : ipv4.py
|
||||
@Software: PyCharm
|
||||
|
|
38
python/port_scan.py
Normal file
38
python/port_scan.py
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user