HowTo find the port on a switch that a host belongs to, the easy way, part 1

 

The Port Report Project is essentially a Switch Port Mapper Tool or a Switch Port Mapping Tool like a few other commercial products out there, except The Port Report Project is free. Right now there is no GUI or WEB interface for the project but it is in the works.

The other day I was speaking to a buddy of mine. I asked him how cool would it be, if you could just get the port on a switch that you are plugged into, in one line?? So since I thought about it… I figured why not…. I just finished writing the first revision ( I’m assuming more to come). I must say that I am quite pleased with it. Right now you can pass the switch you want to talk too, the community string, and either the MAC or IP address of the host device. In return you will get the MAC Address, IP Address, Port Description (VLAN), and Port you are plugged into.

This script requires, Pysnmp and Pyasn1. If you have python-setuptools, you can install it by running this..
easy_install pysnmp, easy_install pyasn1

 

Three things you will need for this script to work..

  1. Pysnmp
  2. Pyasn1
  3. SNMP Access to the switch you want to talk too and its community string.
To make your life easier you should do the following
  1. install python-setuptools
  2. then run easy_install pysnmp
  3. and easy_install pyasn1
  4. or you can download the 2 modules manually.
    pysnmp and pyasn1
  5. then unzip the 2 files and in each directory run python setup.py install

I am using the following revisions from the python cheese shop pysnmp 4.1.7a  and pyasn1 0.0.6a

 

Revision 2, will even add more features like…

  • Trying to find out what is plugged into a certain Port.
  • Passing a list of switches
  • follow chained switches
  • Gettinginfo from non vlan ports.
  • If you have more ideas, please let me know..

Update 1.7….This is a big update for Port Report…. In this revision the following brands and devices are supported

  1. Cisco
    • Catalyst 6509 w/ Supervisor 720 running IOS
    • Catalyst 3560
    • Catalyst 3550 (SMI)
    • Cisco CIGESM series Chassis Blades
    • Cisco Catalyst 2960
  2. Foundry
    • Foundry Server Iron
  3. Nortel
    • Nortel Passport 8600
    • Nortel 5520 Ethernet Routing Switch
  4. HP
    • HP Procurve 5406xl

The Script has been tested with the above devices… If you have run this script against other devices, please let us know. Also the speed in the report function has drastically increased. I ran this script against a 6509 with 800+ devices connected to it in just over 2 minutes.

You can download the script here {quickdown:44}

Update..  revision 1.6 has been released.

  • Support for HP PROCURVE switches
  • Added Verbose option
  • Combined switch_report.py in port_report.py

Update, version 1.4…
Only changes that have been made are below..

  • Code Clean up
  • added check by port name
  • Added Error Checking
  • fixed a few bugs with matching the ifIndex port to the bridgeport

So from the looks of it this script does work on Cisco Switches,which has been tested. But does not work on HP Procurve switches. I would like to add this feature to this script but I do not have HP switches to test on.  If anyone would like me to add this feature to HP switches oranyother manufacturer please let me know and maybe we can work together to get it working.

Please post any questions related to this script here.. http://www.linuxdynasty.org/forums/Scripting/scripting/port_report
You can download the script here… get_port.py

This entry was posted in Port Report Projects, Python and tagged , , , . Bookmark the permalink.

Leave a Reply