-2

To look at some details regarding a ppp connection, one can run the following command:

$ 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)

In order to check if there is any data transfer, one can re-run that command, while paying attention to RX packets and TX packets to see if there is a change (maybe there's a better way of doing this?).

Anyways, I could do the same with Python, but it's cumbersome (using subprocess, and then parsing the output), so am wondering if there's a better way. I would have loved to use netifaces for this, but it provides more limited info:

$ python -c "import netifaces; print netifaces.ifaddresses('ppp0')"
{2: [{'peer': '10.64.64.64', 'netmask': '255.255.255.255', 'addr': '197.108.58.82'}]}
tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

2

You can look up the data in /proc, if that is easier than invoking 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])

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

Robᵩ
  • 163,533
  • 20
  • 239
  • 308