我希望使用python代码确定我的路由器的地址。我发现在安装了netifaces.gateways()库之后,我可以使用这个方法netifaces。
但我的问题是:
rimeh@rimeh-PC:~$ python
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netifaces
>>> gws=netifaces.gateways()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'gateways'我需要帮助,谢谢。
发布于 2015-03-10 12:44:27
gateway()只有在netifaces 0.10.0之后才可用。相反,尝试从子进程调用route命令:
$ python -c 'import subprocess; print subprocess.check_output(["route", "-n"]).splitlines()[2].split()[1]'
192.168.1.1https://askubuntu.com/questions/595027
复制相似问题