gpt4 book ai didi

python - tcpkill : write: Operation not permitted with subprocess. 弹出

转载 作者:太空宇宙 更新时间:2023-11-04 10:27:56 25 4
gpt4 key购买 nike

我正试图从 Python 脚本中终止 TCP 连接。 tcpkill 运行,但在任何数据传输时给出该消息:

tcpkill: write: Operation not permitted
***.***.***.***:48868 > ***.***.***.***:6905: R 1868230658:1868230658(0) win 0

我的 Python 代码是:

    @staticmethod
def kill_connection(ip, interface="eth0"):
def tcp_kill(ip, interface):
logging.info('Killing ' + ip + ' connection with tcpkill.')
p = subprocess.Popen('/sbin/tcpkill -i ' + interface + ' -9 ip host ' + ip, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
time.sleep(30)
p.terminate()

t = threading.Thread(target=tcp_kill, args=(ip, interface))
t.daemon = True
t.start()

我尝试打开/关闭“shell”选项,将预执行功能设置为 os.setguid。没有机会。

手动运行 tcpkill 工作正常。

是什么原因造成的,我该如何让它正常运行?

最佳答案

你会想要将你的 kill 命令放入一个数组而不是一个字符串中。

    @staticmethod
def kill_connection(ip, interface="eth0"):
def tcp_kill(ip, interface):
logging.info('Killing ' + ip + ' connection with tcpkill.')
p = subprocess.Popen(['/sbin/tcpkill', '-i ', interface, '-9', 'ip', 'host', ip],
stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
time.sleep(30)
p.terminate()

t = threading.Thread(target=tcp_kill, args=(ip, interface))
t.daemon = True
t.start()

关于python - tcpkill : write: Operation not permitted with subprocess. 弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40951095/

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