gpt4 book ai didi

python - 遇到端口应用程序阻塞问题

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:03 25 4
gpt4 key购买 nike

关于如何阻止网络端口被使用的任何想法,或者目前正在使用吗?例如,假设我想阻止端口 23正在使用。使用,我的意思是允许与它的连接。

提前致谢。

最佳答案

该解决方案需要通过命令行完成,但是您可以使用 python 的操作系统库来运行脚本。这个link也是一个类似的问题(只是端口不同),因此您可以调整该命令,然后通过以下脚本运行它

import os
# specify the command prompt command you need to be run
command = 'netsh advfirewall firewall add rule name="BlockAIM" protocol=TCP dir=out remoteport=23 action=block'
# assign variable to the command
output = os.popen2(command)
# To get output call output.read()

以下脚本会阻止传出请求,因此您需要使用 dir=in 重复该过程

关于python - 遇到端口应用程序阻塞问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42754802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com