-
Notifications
You must be signed in to change notification settings - Fork 3
/
set-password-serial
executable file
·64 lines (50 loc) · 1.44 KB
/
set-password-serial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/expect
# Get device and port statistics from the switch
# usage: ./set-serial-password device
# Written by Philipp Klaus
set serial [lindex $argv 0]
set newpass [lindex $argv 1]
if { $serial == "" || $newpass == "" } {
puts "Usage: <serial> <new_password>\n"
exit 1
}
set timeout 20
#set spawned [spawn cu -l $serial -s 38400]
#set baud 38400
# -parenb means don't use a parity bit
# -cstopb means "not 2 stop bits, but 1"
# cs8 means 8 bits
# -echo means no echo (full duplex?)
#stty ispeed $baud ospeed $baud raw -echo cs8 -parenb -cstopb onlcr < $serial
#stty -F $serial 38400
#spawn -open [open $serial w+]
#set baud 38400
#stty ispeed 38400 ospeed 38400 cs8 -parenb -parodd -cstopb -raw -echo < $serial
# http://humbledown.org/expect-serial.xhtml
#global spawn_id; # important
puts stderr "Opening serial port"
spawn -noecho -open [open $serial {RDWR NOCTTY NONBLOCK}]
puts stderr "Setting TTY parameters"
stty -f $serial 38400 raw -echo speed 38400 clocal cread cs8 -parenb -parodd -cstopb -crtscts -dsrflow -dtrflow
puts stderr "Terminal configured"
send "exit\r"
send "exit\r"
send "exit\r"
puts stderr "State should be reset by now"
expect ">"
send "enable\r"
expect "#"
send "config\r"
expect "(config)#"
send "line vty 0 5\r"
expect "(config-line)#"
send "login local\r"
expect "(config-line)#"
send "exit\r"
expect "(config)#"
send "enable password $newpass\r"
expect "#"
send "exit\r"
expect "#"
send "exit\r"
expect ">"