2006-02-03

Integer to IP conversion

In what may be the penultimate geek pissing contest, my co-workers and I recently had a competition to see who could generate a dotted-decimal IP address from an integer (a common challenge, for those of us working in the trenches in the networking and infosec world) in a script using the fewest number of commands possible. While I may not be proven in time to be the winner, I'm currently the leader with the following Perl gem:

for($val=$ARGV[0]; $val>0; $val=$val<<8) { printf("%d.",($val & 0xFF000000)>>24) ; }

I was too proud of this to not mention it; although I realize it reinforces any and all notions that I am, in fact, a huge nerd.

Update: I've been struggling with formatting on this entry. Trying pre tags, with the line chopped off in the middle seems to work.