| | Stumble It! | Add to Mixx! | | diigo it | | Slashdot |

Thursday, December 4, 2008

Mass Cisco Device Scanner

I actually got to do some network related work over the last few days and let me tell you how much fun it was! To top it off, I got to flex my (very) rusty BASH scripting muscles.

The Challenge: We need to update the firmware of some of our Cisco network devices.

The Problem: We have MANY of these devices and no current inventory of which devices have what firmware installed (that I know of anyway). So I needed to generate the list of devices that need the update. The simple way is to log into the devices, run a "show version" command and record the firmware version for the device. Repeat that process a couple hundred times and you can see why this is a problem.

The Solution: BASH scripting on Ubuntu Linux. After doing a bit of research & studying other people's scripts to access devices, I managed to pull together a couple scripts to automate the process of logging into a device, running a command, and logging/processing the output. Here's how:
Step 1 - Acquire a list of the devices you want to scan. Put them in the "hosts.txt" file, one per line. You can list them by DNS or IP address.
Step 2 - Put the commands you want to run on the hosts into the "cmds.txt" file. One per line just like you were executing them yourself.
Step 3 - From your Linux box (I used Ubuntu on my EeePC) run the "./ciscoScanner.sh" script like this:
./ciscoScanner.sh USERNAME PASSWORD text|to|find
Step 4 - Monitor the progress in the terminal window.
Step 5 - When the script is done you'll have a file named "[date].scan.log" with only the lines from the fields you put in "text|to|find". You can then parse this in Excel or any other method that's convenient for you.
You can download the scripts in a .zip file here.

I used these scripts successfully on Ubuntu 8.04 (Hardy Heron). You'll need to install the most current version of "expect", "ssh", & "telnet". I did some basic testing with cygwin and met with limited success, though it shouldn't be that difficult to solve for someone with a bit more experience than I.

0 comments: