启用防火墙时,端口扫描失败

时间:2018-04-26 02:28:41

标签: python windows networking windows-firewall

我有Windows客户端系统环境,当我使用以下命令进行端口扫描时,如果打开防火墙,则不会得到响应。

Q1。我想知道是否有任何方法我可以在防火墙开启时获得响应? Q2。任何端口总是在Windows系统中打开,以便我可以得到响应。

注意:禁用防火墙选项不适合我,因为我更改计算机域设置防火墙默认为防火墙中的域网络打开

enter image description here

import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ClientIP = '10.xxx.xxx.xxx'
def portscanner(port):
    try:
        s.connect((ClientIP,port))
        return True
    except:
        return False
for x in range(8000,8003):
    if portscanner(x):
        print("Port is open",x)
    else:
        print("port is closed",x)

1 个答案:

答案 0 :(得分:1)

当端口被防火墙阻止时,您无法在超时之前检测到故障。您可以设置一个短暂的超时。

s.settimeout(1);

这只会在放弃之前等待1秒钟。