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'

Sunday, February 24, 2008

Easy Win32 Python and Registry

So I have some experience with APIs for accessing the registry (when I wrote some SCADA Nessus Plugins) but it can't get any easier than this recipe.

Sunday, January 13, 2008

NetworkX: This I might actually find time to play with



Just ran across NetworkX tonight:


NetworkX (NX) is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. Features: Includes standard graph-theoretic and statistical physics functions, Easy exchange of network algorithms between applications, disciplines, and platforms, Includes many classic graphs and synthetic networks, Nodes and edges can be "anything" (e.g. time-series, text, images, XML records)

Friday, January 4, 2008

A Better Python Cmd Library

The Python cmd module has always been been better than the Ruby imitation (after all like most things about Ruby, it is cheap copy of the original, distinctive feel?) but cmd2 turns this into a real ass-kicking with the following features:


* Searchable command history (commands: "hi", "li", "run")
* Load commands from file, save to file, edit commands in file
* Multi-line commands
* Case-insensitive commands
* Special-character shortcut commands (beyond cmd's "@" and "!")
* Settable environment parameters
* Parsing commands with flags

Django on Jython?

I previously whined about the non-progress of Jython (especially relative to JRuby) but this is great news.

The most important thing to know about Django on Jython is that we are almost there, and with clean code. End-to-end functionality is demonstrated by the admin tool running in full CRUD, along with a substantial number of unit tests and syncdb.

Wednesday, January 2, 2008

Maybe someday I'll have time to read on Python Bytecode

Maybe someday I'll get a chance to fully digestExploring Python Bytecode.


For the past month or so, I’ve been trying to understand what appears to be a black art mostly because of lacking documentation - Python bytecode generation and peephole optimization. Some notes from the study for the benefit of IRC-mate ‘jstatm’ and anyone else living on similar planes of insanity.

Although bytecode applies to objects other than functions such as tracebacks, dictionaries and strings, I am only interested in optimization and flow analysis of class methods, functions and lambdas. Lets get to the action straight away with an example. Here is a small python program to disassemble and display the bytecode of a function in human readable form.

Tuesday, January 1, 2008

Decorators, Python Black Magic and the Residue of Past Programming

While trying to figure out decorators I ran across a really cool presentation called Python Black Magic (or how I learned to stop writing Java in Python). I understand this, since much of the Python I've written over the years, was even worse -- I was writing Perl in Python. For the longest time Python OO conventions seemed strange compared to Java/C# and I refused to use them sticking to horrific Perl-like hash of a hash of a hash data structures. On the one hand if you are sort of programming-ADD-like-me, I definitely see the advantage of developing a set of crisp clean, language agnostic design patters. Who cares if your code isn't completely Pythonic or if you aren't exploiting all the Ruby functional programming fu, your code will be accessible to the largest possible audience.