Sunday, March 2, 2008

fun with ieeemac

This week I count have actually used ieeemac when I was writing some scripts to automate packet generation using Click Router.

But of course I was using Ruby so I couldn't take advantage of this.

>>> import ieeemac
>>> import commands
>>> o = commands.getoutput("ifconfig -a")
>>> o
'lo0: flags=8049 mtu 16384\n\tinet 127.0.0.1 netmask 0xff000000 \n\tinet6 ::1 prefixlen 128 \n\tinet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 \ngif0: flags=8010 mtu 1280\nstf0: flags=0<> mtu 1280\nen0: flags=8863 mtu 1500\n\tether 00:11:24:45:4b:1a \n\tmedia: autoselect (none) status: inactive\n\tsupported media: none autoselect 10baseT/UTP 10baseT/UTP 10baseT/UTP 100baseTX 100baseTX 100baseTX \nen1: flags=8863 mtu 1500\n\tinet6 fe80::211:24ff:fea4:9fc7%en1 prefixlen 64 scopeid 0x5 \n\tinet 192.168.1.103 netmask 0xffffff00 broadcast 192.168.1.255\n\tether 00:11:24:a4:9f:c7 \n\tmedia: autoselect status: active\n\tsupported media: autoselect\nfw0: flags=8863 mtu 2030\n\tlladdr 00:11:24:ff:fe:45:4b:1a \n\tmedia: autoselect status: inactive\n\tsupported media: autoselect \nwlt1: flags=41 mtu 1500\ntap0: flags=8842 mtu 1500\n\tether 74:61:70:00:00:00 \n\tclosed\ntun0: flags=8850 mtu 1500\n\tclosed'
>>> ieeemac.find_macs(o)
[, , , ]
>>> ml = ieeemac.find_macs(o)
>>> ml
[, , , ]
>>> ml[0]

>>> dir(ml[0])
['__doc__', '__eq__', '__getattr__', '__init__', '__module__', '__str__', '_formats', 'format', 'formats', 'groups', 'groups_need_fixing', 'to_format']
>>> ml[0].to_format("cisco")
'0011.2445.4b1a'

2 comments:

Bill Marquette said...

Just for fun, I decided to try my hand at writing this class in ruby. Check out http://www.rubyfindings.com/articles/2008/03/31/ieeemac-rb-why-let-python-have-all-the-fun for my interpretation :)

Bill Marquette said...

Yikes, must pay attention to input boxes and maybe hit preview once in a while. Try ieeemac.rb why let python have all the fun