Tuesday, May 22, 2018

[Cisco] I wrote a script that will take an IP address and give return the edge switch and port to which it's connected

hey everyone,

after finding myself manually going through the process of taking an IP, getting its MAC, then checking MAC tables to find what switch and port the device is connected to, I wrote a Python script to automate the process.

https://github.com/routetehpacketz/cisco-ip-trace

here's an excerpt from the README that explains its usage:

-Open a command prompt/terminal and run cisco_ip_trace.py

-Fill out the following prompts:

Enter the IP address of the core router/switch that can ARP for the IP address to scan: Enter IP address to trace: Username: Password: 

-Press Enter

The script will then use a series of show commands and regexes against the outputs to identify the port the associated MAC address is learned on, determine if there is another Cisco switch connected via CDP, and continues the trace until it reaches a port where no switch is detected. It will then print its findings like this:

10.1.10.10,000.abcd.ef12,SwitchA,Gi1/0/1

currently this script is currently only designed to work on Cisco devices, but I intend to continuously find ways of improving this script and hope to provide support for other platforms. please see the github page for a more complete list of requirements and known issues.

I greatly appreciate any feedback, positive or negative, and I hope this script is useful to at least one person on here. please let me know what you think! thanks!



No comments:

Post a Comment