summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
74b9275)
En util.py se corrige get_network_devices para que
levante los link/ppp.
En ip/__init__.py se agrega refresh_devices para que
a travez del handle_timer se puedan agregar los devices
que se registran a travez del commando ppp y tambien
se borren los devices caidos.
+ def handle_timer(self):
+ self.refresh_devices()
+
+
+ def refresh_devices(self):
+ devices = get_network_devices()
+ #add not registered devices
+ for k,v in devices.items():
+ if k not in self.devices:
+ self.devices[k] = Device(k,v)
+ #delete dead devices
+ for k in self.devices.keys():
+ if k not in devices:
+ del self.devices[k]
+
+
+
if __name__ == '__main__':
if __name__ == '__main__':
print '----------------------'
ip.hop.add('201.21.32.53','eth0')
ip.hop.add('205.65.65.25','eth1')
print '----------------------'
ip.hop.add('201.21.32.53','eth0')
ip.hop.add('205.65.65.25','eth1')
if __name__ == '__main__':
if __name__ == '__main__':
p = PppHandler()
p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0')
p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1')
p = PppHandler()
p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0')
p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1')
def get_network_devices():
def get_network_devices():
- p = subprocess.Popen(('ip', 'link', 'list'), stdout=subprocess.PIPE,
+ p = subprocess.Popen(('ip', '-o', 'link'), stdout=subprocess.PIPE,
close_fds=True)
string = p.stdout.read()
p.wait()
d = dict()
close_fds=True)
string = p.stdout.read()
p.wait()
d = dict()
- 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(':',2)
+ name = dev[3: i]
+ d[name] = mac
+ elif dev.find('link/ppp') != -1:
+ i = dev.find('link/ppp')
+ mac = '00:00:00:00:00:00'
+ i = dev.find(':',2)
+ name = dev[3 : i]
+ d[name] = mac
return d
def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
return d
def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,