Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

There are some Cisco and Juniper devices on our network that I need to make a python script to determine what they are: switches or routers.

I have ssh access, so I can show version and parse 'JUNOS' or 'Cisco' to find out the vendor. But I don't know how to find out if the device is a router, switch or something else.

Thanks for you help!

share|improve this question
3  
I think you should not face such an issue if you have a meaningful name of each device. –  Khaled Jan 2 '13 at 14:03
    
I wish nmap -O were more accurate. Running against a Cisco firewall gives: "Device type: firewall - Running (JUST GUESSING): Juniper embedded (88%), Cisco PIX OS 7.X (87%)". –  ewwhite Jan 2 '13 at 14:22

3 Answers 3

It can be quite hard to tell because a lot of models marketed as a switch will have routing functions included, and you could also have cases where routers are being used like switches - i.e. they aren't routing traffic. So even if you can figure out the capability of a device, you really want to know its function in your network.

You might have a lot of devices, but you probably don't have that many different models, so manually parsing the output of show version may be enough to figure out what your devices can do.

Unless you are just trying to populate an asset database, you are going to have to look at the configurations and figure out what each device is actually configured to do.

share|improve this answer
    
You are right, the function might differ from the original purpose of the device. Unfortunately it is an asset database we are populating, and I get 1200+ Cisco and 500+ Juniper matches out there. Reading more I found that all Juniper Switches are EX series, which might be helpful for parsing. –  pr1va Jan 2 '13 at 14:34
    
Just out of interest, how many unique results do you get for those 1700 devices. I'd be tempted to just argue for a category of Network Device in your asset database if the number of models is very high... Of course they are next going to ask for the purchase amount and date for each one which programming may not help you with. –  dunxd Jan 2 '13 at 14:46
    
Those are matches, not devices. Some hosts get up to 15 matches, 5 of those might be Cisco's, 5 Juniper's and 5 miscellaneous. –  pr1va Jan 2 '13 at 14:54
    
Sorry, I forgot to mention that I'm dealing with an nmap output here. –  pr1va Jan 2 '13 at 15:07

On a Cisco device, can parse the device capabilities using CDP ( see On a cisco device, how do you show the capabilities? ) however you might have CDP disabled on your network.

The best would be to check if Vlan interfaces are present (means a switching-able device) and if fastEthernet X/X/X type interfaces exist ( likely a switching-able router ).

By using these two facts, you get a quite accurate idea of what the device is, but it is Cisco specific.

You can also use the Cisco feature navigator / Juniper reference to construct a detection using the model name ( If you know which devices you have on you network, most of the times you have a limited quantity of models ), which will be more accurate but specific to your network.

The advantage is that this time it is generic and not specific to one brand, and there is no risk of a wrong detection.

Alternatively, you might want to use a CMDB or an inventory software to prepare this information for later use, then you would just have to query your database to check wether is a switch or a router.

share|improve this answer

There are lots of ways to do this.

My first choice would be SNMP even if you have to try multiple strings. The calls are quicker and less vulnerable to differences in code version. You could download a free copy of solar winds and be finished in less than an hour. It's also much easier to script SNMP interaction than ssh/cli.

Next I would use some kind of expect wrapper. I'm partial to the perl stuff because it's more stable and more well documented. You can also write an expect script and call it from python.

show version is the obvious command but it it can differ between devices. Do you have a list of the possible platforms? You can use regexes to sort from a give list and then put everything else into an unknown pile. As you sort the unknowns update your script to find them automatically.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.