【发布时间】:2013-10-23 20:01:04
【问题描述】:
要查看有关 ppp 连接的一些详细信息,可以运行以下命令:
$ ifconfig ppp
ppp0 Link encap:Point-to-Point Protocol
inet addr:197.108.58.82 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:479 errors:0 dropped:0 overruns:0 frame:0
TX packets:479 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:68118 (68.1 KB) TX bytes:32771 (32.7 KB)
为了检查是否有数据传输,可以重新运行该命令,同时注意RX包和TX包看是否有改变(也许有更好的方法?)。
无论如何,我可以用 Python 做同样的事情,但它很麻烦(使用 subprocess,然后解析输出),所以想知道是否有更好的方法。我很想为此使用netifaces,但它提供的信息更有限:
$ python -c "import netifaces; print netifaces.ifaddresses('ppp0')"
{2: [{'peer': '10.64.64.64', 'netmask': '255.255.255.255', 'addr': '197.108.58.82'}]}
【问题讨论】: