Index: /tools/check-batch-cmd
===================================================================
--- /tools/check-batch-cmd	(revision 11947)
+++ /tools/check-batch-cmd	(revision 11950)
@@ -11,6 +11,7 @@
 import os
 import paramiko
+import socket
+import struct
 import subprocess
-import socket
 import sys
 import time
@@ -69,4 +70,40 @@
   else:
     return filter(None, retval)[0]
+
+
+# http://countergram.com/python-group-iterator-list-function
+def group_iter(iterator, n=2, strict=False):
+    """ Transforms a sequence of values into a sequence of n-tuples.
+    e.g. [1, 2, 3, 4, ...] => [(1, 2), (3, 4), ...] (when n == 2)
+    If strict, then it will raise ValueError if there is a group of fewer
+    than n items at the end of the sequence. """
+    accumulator = []
+    for item in iterator:
+        accumulator.append(item)
+        if len(accumulator) == n: # tested as fast as separate counter
+            yield tuple(accumulator)
+            accumulator = [] # tested faster than accumulator[:] = []
+            # and tested as fast as re-using one list object
+    if strict and len(accumulator) != 0:
+        raise ValueError("Leftover values")
+
+
+def get_bridge_mac(host):
+  """ Both NS and NS Mx uses a slighly different OID"""
+  var_list = netsnmp.VarList(
+   *map(lambda x: netsnmp.Varbind(x), 
+    ['IF-MIB::ifDescr','IF-MIB::ifPhysAddress']))
+  sess = netsnmp.Session(Version=1, DestHost=host, Community='public', Timeout=6 * 100000, Retries=1)
+  retval = sess.walk(var_list)
+  if sess.ErrorInd < 0:
+    raise CmdError('SNMP Failed -- [%(ErrorInd)s] %(ErrorStr)s (%(DestHost)s)' % vars(sess))
+  if not filter(None, retval):
+    return None
+  else:
+    # We only have bridge configurations, so looking at bridge MAC addresses
+    mac_raw = dict(group_iter(retval,2))['br0']
+    return ':'.join(map(lambda x: "%02x" % x,struct.unpack("BBBBBB",mac_raw)))
+
+
 
 
@@ -97,6 +134,10 @@
       try:
         socket.create_connection((addr,80),2)
+        bridge_mac = get_bridge_mac(addr)
+        if bridge_mac:
+          datadump[iface_key]['ns_mac'] = bridge_mac
         bridge_type = get_bridge_type(addr)
-        datadump[iface_key]['bridge_type'] = bridge_type
+        if bridge_type:
+          datadump[iface_key]['bridge_type'] = bridge_type
       except (socket.timeout, socket.error) as e:
         print "### %s (%s)" % (e, addr)
