Blog |Follow Nick on Twitter| About
 

Recently I wrote a python script for converting mac addresses (which you can download from github) and the reason I wrote it is because I receive emails like this...

email_with_mac

The background is, I'm working on an 802.1x project, I need to find the printer, the quickest solution in this case is to look in the ARP cache of the router/switch on site.

The irritant is that in the email the MAC is in EUI format, but routers/switches are in Cisco's. To Further irritate, Cisco ISE and ACS use EUI format so if someone sends you a MAC address from a switch or their windows machine then you need to convert it, I've spent a lot of time replacing dots and dashes :D

Today, I realised that I could use Apple's Automator to grab text from somewhere... I could then parse it through my python scripts and have the results in my clip board... ready for pasting!

Below is my automator workflow

Automator_-_Convert_to_EUI_MAC

In the python field you can't see the full text... paste in this...

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
import sys

addr=str(sys.argv[1])

if "." in addr:
    delimiter = "."
elif ":" in addr:
    delimiter = ":"
elif "-" in addr:
    delimiter = "-"

# Eliminate the delimiter
m = addr.replace(delimiter, "")

# Normalise Case
m = m.lower()
u = m.upper()

eui= ":".join(["%s%s" % (m[i], m[i+1]) for i in range(0,12,2)])

print eui

If you've having issues creating a new automator service from the screenshot I have uploaded my Convert to EUI MAC.workflow save it to ~/Library/Services

Once you're all setup, you'll be able to right click any mac address and convert it. I've also created a Convert to Cisco MAC.workflow if you need it in router/switch format.

 

 
Nick Bettison ©