pycharm程序实现全连接端口扫描
时间: 2023-11-13 17:57:21 浏览: 79
好的,以下是实现全连接端口扫描的代码:
```python
import socket
def scan_ports(host, start_port, end_port):
for port in range(start_port, end_port+1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((host, port))
print(f"Port {port} is open")
except:
pass
s.close()
if __name__ == '__main__':
host = input("Enter the host to be scanned: ")
start_port = int(input("Enter the starting port number: "))
end_port = int(input("Enter the ending port number: "))
scan_ports(host, start_port, end_port)
```
这个程序使用了 Python 的 socket 模块,通过循环扫描指定范围内的端口,如果端口是开放的,则打印出来。
阅读全文