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.

3 comments:

GrizzlyAdamz said...

Sounds like you work with a lot of smart people. :) Well, at least most of them are probably smart..the others are just hanging on for the ride. *whistling*

Keith said...

So, you can feel not so bad. While it might prove that you're a nerd the fact that I got excited about it proves I have no room to make a negative comment.

Good work...

Ron said...

I needed a script for converting integers to IP so I used this one from my Google search. thanks.