Cisco

Autologin auf Cisco-Switch mittels expect

Dieses Script ermöglicht einen automatischen Login auf Cisco-Switche inkl. automatischem „enable“ (sofern die beiden Kennwörter gleich sind).

#!/usr/bin/expect -f
#######################################
## Update Router Config
#######################################
set host [lindex $argv 0]
set pw XXXX
trap exit {SIGINT SIGTERM}
spawn telnet $host

expect {
"Username: " {
        send "root\r"
	exp_continue
}
"Password: " {
        send "$pw\r"
}
timeout {
        send_user "\n\ntimeout...\n"
        exit 1
}
}

expect {
"% " {
        send_user "\n\nlogin failed.\n"
        exit 1
}
">" {  
        send "enable\r"
}
}

expect {
"Password: " {
        send "$pw\r"
}
timeout {
        send_user "\n\ntimeout...\n"
        exit 1
}
}

expect {
"% " {
        send_user "\n\nenable failed.\n"
        exit 1
}
"#" {
	send_user "\nlogged in...\n"
	send "\n"
}
}

interact

Grundlegende Befehle

  1. telnet cisco.xxx.de
  2. Passwort eingeben
  3. en (enable) + Enable-Passwort

im Enable-Modus:

  • show running config (sh run) → laufende Konfiguration ankucken
  • show interface fa0/1 (sh int fa0/1) → einzelnes Interface ankucken (mit erweiterter Anzeige)
  • show ip int brief → kurze Übersicht über alle Interfaces
  • show logging → Logeinträge des Gerätes anzeigen

im Konfigurations-Modus:

Port Trunking

zuerst auf dem Cisco-Switch einloggen, enable-Mode aktivieren und in den Konfigurationsmodus für das gewünschte Interface wechseln

[user@bla:~]$ telnet cisco1.domain.de
Trying 192.168.100.1...
Connected to cisco1.domain.de.
Escape character is '^]'.


User Access Verification

Password: 
Name:           cisco1
Model:          WS-C3524-XL-EN
Eigentum:       Kunde
Standort:       RZ1

cisco1>en
Password: 
cisco1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
cisco1(config)#interface FastEthernet0/1
cisco1(config-if)#

Einschalten

switchport trunk encapsulation dot1q
switchport trunk allowed vlan 760,761,...
switchport mode trunk

Ausschalten

no switchport trunk allowed vlan 760,761,...
no switchport mode trunk
no switchport trunk encapsulation
switchport mode access
switchport access vlan 760