diff options
-rw-r--r-- | haircontrol/discovery.py | 18 | ||||
-rw-r--r-- | haircontrol/inspectors.py | 12 |
2 files changed, 27 insertions, 3 deletions
diff --git a/haircontrol/discovery.py b/haircontrol/discovery.py index a9639be..3180ace 100644 --- a/haircontrol/discovery.py +++ b/haircontrol/discovery.py @@ -167,13 +167,25 @@ class Discovery: # Inspect switches elif isinstance(i, ToughSwitchInspector): - result = i.command('mactable_data.cgi') - for (ifname, mac) in result: - e.add_seen_mac(ifname, mac) + result = i.command('ip-link') + switch_mac = '?' + for (ifname, mac) in result: + if ifname == 'br0': # XXX configurable filter + switch_mac = mac + result = i.command('mactable_data.cgi') + for (ifname, mac) in result: + e.add_iface(ifname, switch_mac) # XXX many non-usefull calls + e.add_seen_mac(ifname, mac) elif isinstance(i, EdgeMaxInspector): + switch_mac = '?' + result = i.command('show-version') + for (key, value) in result: + if key == 'Burned In MAC Address': + switch_mac = value result = i.command('mac-addr-table') for (mac, ifname) in result: + e.add_iface(ifname, switch_mac) # XXX many non-usefull calls e.add_seen_mac(ifname, mac) else: print("Notice: Nothing inspected on %s"%e) diff --git a/haircontrol/inspectors.py b/haircontrol/inspectors.py index 04b05c1..c5c6940 100644 --- a/haircontrol/inspectors.py +++ b/haircontrol/inspectors.py @@ -180,6 +180,13 @@ class ToughSwitchInspector(Inspector): 'cmd':'/usr/www/mactable_data.cgi', 'func': parse_mactable_data_cgi }, + 'ip-link': { + 'cmd': 'ip -o link', + 'kind': 'text', + 're': re.compile("\d+:\s+(?P<ifname>[^:]*):.+\s+(?:link/ether\s+(?P<mac>[a-f0-9:]*)\s+brd|link/none)") + # 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default \ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + # 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000\ link/ether 8c:89:a5:c7:be:88 brd ff:ff:ff:ff:ff:ff + }, } class EdgeMaxInspector(Inspector): @@ -192,6 +199,11 @@ class EdgeMaxInspector(Inspector): # 1 00:15:6D:8E:22:46 0/15 15 Learned # 1 00:27:22:0E:67:F9 0/17 17 Learned }, + 'show-version': { + 'cmd':'show version', #XXX needs "enable" mode + 're': re.compile("(?P<key>[^\.]+)\.+ (?P<value>.*)") + # Burned In MAC Address.......................... 44:D9:E7:51:BF:A7 + }, } #TODO Implement them |