- i = string.find('eth')
- while i != -1:
- eth = string[i:i+4]
- m = string.find('link/ether', i+4)
- mac = string[ m+11 : m+11+17]
- d[eth] = mac
- i = string.find('eth', m+11+17)
+ devices = string.splitlines()
+ for dev in devices:
+ mac = ''
+ if dev.find('link/ether') != -1:
+ i = dev.find('link/ether')
+ mac = dev[i+11 : i+11+17]
+ i = dev.find(':')
+ j = dev.find(':', i+1)
+ name = dev[i+2: j]
+ d[name] = Device(name,mac,False)
+ elif dev.find('link/ppp') != -1:
+ i = dev.find('link/ppp')
+ mac = '00:00:00:00:00:00'
+ i = dev.find(':')
+ j = dev.find(':', i+1)
+ name = dev[i+2 : j]
+ d[name] = Device(name,mac,True)
+ #since the device is ppp, get the address and peer
+ try:
+ p = subprocess.Popen(('ip', '-o', 'addr', 'show', name), stdout=subprocess.PIPE,
+ close_fds=True, stderr=subprocess.PIPE)
+ string = p.stdout.read()
+ p.wait()
+ addrs = string.splitlines()
+ inet = addrs[1].find('inet')
+ peer = addrs[1].find('peer')
+ bar = addrs[1].find('/')
+ from_addr = addrs[1][inet+5 : peer-1]
+ to_addr = addrs[1][peer+5 : bar]
+ d[name].addrs[from_addr] = Address(from_addr,24, peer=to_addr)
+ except IndexError:
+ pass