【问题标题】:How to check if ppp connection is busy如何检查ppp连接是否繁忙
【发布时间】: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'}]}

【问题讨论】:

    标签: python linux debian ppp


    【解决方案1】:

    您可以在/proc 中查找数据,如果这比调用ifconfig 更容易的话。

    def GetPacketCount(dev_name):
        '''Return (received_packets, transmitted_packets) for network device dev_name'''
        with open('/proc/net/dev') as fp:
            for line in fp:
                line = line.split()
                if line[0].startswith(dev_name):
                    return int(line[2]), int(line[10])
    
    if __name__ == '__main__':
        import sys
        print GetPacketCount(sys.argv[1])
    

    参考:https://www.kernel.org/doc/Documentation/filesystems/proc.txt

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 2018-03-21
      • 1970-01-01
      相关资源
      最近更新 更多