命令行下开启与关闭windows防火墙关端口(转)

时间:2021-02-22 01:09:55

sc config sharedaccess start= auto //设置防火墙服务为自动

net start sharedaccess //开启防火墙服务

关闭端口

netsh firewall add portopening protocol = TCP port = 139 name = "关闭139" mode = DISABLE

netsh firewall add portopening protocol = TCP port = 445 name = "关闭445" mode = DISABLE

netsh firewall add portopening protocol = UDP port = 137 name = "关闭137" mode = DISABLE

netsh firewall add portopening protocol = UDP port = 138 name = "关闭138" mode = DISABLE

开启端口

netsh firewall add portopening protocol = TCP port = 139 name = "开启139" mode = ENABLE

netsh firewall add portopening protocol = TCP port = 445 name = "开启445" mode =  ENABLE

netsh firewall add portopening protocol = UDP port = 137 name = "开启137" mode =  ENABLE

netsh firewall add portopening protocol = UDP port = 138 name = "开启138" mode =  ENABLE