我试图以非root用户身份运行python-iptables。
我的脚本是test.py:
import iptc
import os
uid = os.getuid()
print("Real user ID of the current process:", uid)
table = iptc.Table(iptc.Table.FILTER)
print("Table is:".format(table))
我尝试过:
/usr/bin/python2.7
(结果是:$ getcap /usr/bin/python2.7 /usr/bin/python2.7 = cap_net_admin+eip
)并按照Python Scapy sniff without root /usr/bin/python2.7 ./test.py
./ambient -c '12' /usr/bin/python2.7 ./test.py
日志为:
('Real user ID of the current process:', 1000)
Traceback (most recent call last):
File "test.py", line 7, in <module>
table = iptc.Table(iptc.Table.FILTER)
File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 1566, in __new__
obj._init(name, autocommit)
File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 1582, in _init
self.refresh()
File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 1619, in refresh
self.strerror()))
iptc.ip4tc.IPTCError: can't initialize filter: Permission denied (you must be root)
我的内核是:
$ uname -r
4.4.224-1.el7.elrepo.x86_64
我的python版本是:
Python 2.7.5
我的python-iptables版本是:
python-iptables 0.12.0
我可以以非root用户身份成功运行“ iptables -L”,但不能以非root用户身份成功运行iptc python命令。
是否还有其他方法可以提供我的python脚本功能,或者它与iptc代码有关?
是否会因为需要其他功能而失败?