📜 ⬆️ ⬇️

Convenient viewing of MAC addresses on ports of switches huawei, linksys, dlink, extreme using expect

Every day, interacting with tech support, you have to climb up the switches and look at the maki. In principle, nothing complicated, but I wanted to beg for work to do something.

Mastered the expect and immediately into battle. Wrote, tried, turned out. Now I share with you, maybe someone will come in handy.

First create an empty file: nano ./get_mac.sh

Now you need to paste the code below into it:
')
#!/usr/bin/expect -f if {[llength $argv] != 2} { puts "  : ./get_mac 10.5.X.XXX 'port'" exit 1 } set ip [lindex $argv 0] set eth [lindex $argv 1] set login "  " set pass "" package require Expect spawn telnet $ip expect { "*assw*" { send "$pass\n" expect "*>" send "su\n" expect "*ass*" send "$pass\n" expect "*>" send "disp mac-addr dy | inc $eth\n" expect "*>" send "q\n"} "*User Name*" { send "$login\n" expect "*asswor*" send "$pass\n" expect "*#" send "show brid address-table ethernet e$eth\n" expect "*#" send "exit\n"} "*login*" { send "admin\n" expect "*password*" send "$pass\n" expect "*#*" send "show fdb port $eth\n" expect "*#*" send "exit\n"} "*Name*" { send "$login\n" expect "*Word*" send "$pass\n" expect "*#" send "show fdb port $eth\n" expect "*#" send "logo\n"} } interact 

Now consider how it works.

In the command line, you need to write a script call, ip of your switch, and the port on which we want to see the MAC: ./get_mac.sh 10.5.0.10 1

After which the script will run. An overview will analyze the input value. Depending on the greeting, the desired code segment will be executed.

Huawei switches have a feature. You can read the fdb table dynamically and sort by the contained value. Therefore, it is recommended to specify the port parameter more precisely for these switches. For example Eth0 / 0 / Port number or 0/0 / Port number . Otherwise, the script will dump all the poppies that contain the variable and the script may crash due to waiting.

This script is tested on pieces of hardware huawei s2326TP-EI, dlink des-3028, linksys sr224g4 and extreme summit 200-24. In theory, it will work on dlink'ah other series such as 32.35 and cisco.

Source: https://habr.com/ru/post/271867/


All Articles