+br = mechanize.Browser()
+br.add_client_certificate("https://nic.mit.edu", cert_file, cert_file)
+
+def get_owner(mac):
+ for lookup in ('host', 'less'):
+ try:
+ data = urllib.urlencode({
+ 'action': 'Lookup Host',
+ 'lookup': lookup,
+ 'mac': mac
+ })
+ br.open('https://nic.mit.edu/bin/dynareg',
+ data)
+ soup = BeautifulSoup.BeautifulSoup(br.response().read())
+ for tag in soup.findAll('td'):
+ if tag.string == 'owner:':
+ return tag.nextSibling.string or \
+ tag.nextSibling.contents[0]['value']
+ except:
+ pass
+ return None
+
+def show_mac(mac, (t, owner)):
+ return '%s (%s)' % (mac, 'unknown owner' if owner is None else owner)
+
+def show_macs():
+ return ', '.join(show_mac(mac, v) for mac, v in seen_macs.iteritems())
+