Archive

Posts Tagged ‘ipconfig’

IPConfig Output to CSV Tool

September 8th, 2009

Alright, so it has been a long, long, time since I have posted. Well that is why I am coming back with a bang (I guess that depends on how easily excite - able you really are). I am currently working on a project to perform some basic infrastructure cleanup. Nevertheless, part of this clean up is to validate that the servers are configured optimally for an impending DNS upgrade. Well that seems straight forward enough, except these are Windows 2000, and 2003 servers, and I need to validate the DNS Suffix List and DNS Search Order. So quickly looking out on the Internet, I found a common vb object, that honestly produced mixed results depending on the server. I just kept thinking all I need is the same data you get from ipconfig /all.
So after capturing the output from ipconfig /all, I decided I needed some way to parse the data. This quickly turned into a small programming opportunity. Amongst the limitless language possibilities, I wrote this program in java. My motivation was based on familiarity, and interest, as performance is not an issue, (give it a whirl you will see).

The Lessons (if you are not interested in the programming, skip to The Execution section)

The Reg Exp a very powerful tool, worthy of its own books (I believe there is an O’Reilly book out there). Regular Expressions, are really powerful, and surprisingly frustrating. That being said, they are a necessary evil, and can be used in most languages today. There gets to be a point of absurdness on traditional find functions, that requires too many conditional expressions. What’s nice, is that these kinds of conditionals can be performed within the Reg Exp, which, in theory, improves readability. My take on it, is you need to use tools. I use jedit as my normal text editor and it has plugins to help formulate the Reg Exp. I also discovered - http://www.regexplanet.com/simple/index.jsp, this site actually will help build out the Java Matcher class string.

The Enum is actually a really great programming enhancement (circa JDK 1.5). I never used it before (in java), and I thought it would be a good opportunity for exposure. It makes for a very clever way of organizing elements in an array. My only thought is it would have been more novel possibly to use a dynamic enum to allow for a variable number of adapters. The problem with that is I would have sacrificed the ability to change the output layout order by simply moving the elements of the enum around, which is quite simple and intuitive.

The Buffered Writer is a very common tool, that I have used many times. The problem is that as a hobbyist I had never really given any thought about the buffer, in the bufferedwriter class. Why, well I honestly didn’t really care, until magically I could only seem to get through 164 servers. After that clearly there was a lot of brain cells churning on the accursed number 165. Which of course there was no issue with. All I have to say is listen to your mom and flush (more appropriately BufferedWriter.flush()).

The Debugger I always figured was just another name for System.out.println :). Actually I have used one before, but I have perpetuated my hobby-ist status by using System.out.println, and as a matter of fact left almost all of mine in commented out. But the debugger truly is your friend. If I become extremely motivated, or more appropriately write something that warrants it, I will try the logging API.

If you are interested in this GPL v2.0 released code, it can be gleaned here. Shoot me an email and let me know where it evolves. Or if you have a need and no programming interest shoot me an email and I will look into it. As always, I am still tekgnu at this domain :).

The Execution

So I need to restate I have run this against Windows 2000, and 2003 servers (I did a cursory test of a vista laptop also with no issues). If there are any bugs or if you have any need for enhancements please let me know. Again, I am tekgnu at this domain.

You can download just the tool here.

To unleash this tool on a directory that contains your ipconfig /all files all you need to do is:

java -jar “/directory/path/to/this/jarfile/ipconfigParser.jar” “/Directory/To/Scan/” optional_output_file.csv

This should capture your data and dump it into your .csv file. If you don’t provide an output file then it gets dumped to standard out.

Good luck, and as always feel free to email!

- - tekgnu - -

tekgnu General, OpenSource, Programming ,