【问题标题】:Python pxssh execute iptables not workingPython pxssh 执行 iptables 不起作用
【发布时间】:2017-08-02 13:42:50
【问题描述】:

我正在使用pxssh 建立与服务器的 SSH 连接。可以建立连接,我可以运行简单的命令,例如ls -l

我现在需要的是通过该 SSH 连接创建 iptable 条目。 我已经尝试了以下

s = pxssh.pxssh()

print(ip)
if not s.login(ip, username, auth_password):
    Log("SSH session failed on login")
    Log(str(s))
else:
    Log("SSH session login successful")
    cmd = 'sudo iptables -I INPUT -p udp -m udp --dport 53 -j ACCEPT;'
    s.sendline(cmd)
    s.prompt()         
    print(s.before) 
    s.logout()

它运行没有错误,但是连接到服务器时,没有创建任何iptable条目!?

【问题讨论】:

    标签: python iptables pxssh


    【解决方案1】:

    尝试像这样修改你的 python 脚本:

    cmd = '/usr/bin/sudo /usr/sbin/iptables -I INPUT -p udp -m udp --dport 53 -j ACCEPT'
    s.sendline(cmd)
    

    如果您的操作系统上的 sudo 和 iptables 路径不同,您应该更改它

    还可以尝试打印 s.sendline(cmd) 以查看通过服务器上的 ptyhon 脚本实际执行的内容,以确保执行了正确的 iptables 命令

    【讨论】:

      猜你喜欢
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      相关资源
      最近更新 更多