Last active
April 26, 2016 05:35
-
-
Save jbsilva/557cfc90138a8bb44d498d78e5a943ba to your computer and use it in GitHub Desktop.
Reconnects my ADSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
set timeout 20 | |
log_file reconnect.log | |
log_user 0 | |
exp_internal 0 | |
if {[llength $argv] == 0} { | |
send_user "Usage: reconnect \'password\'\n" | |
exit 1 | |
} | |
proc get_ip {} { | |
send "net\r" | |
expect "net> " | |
send "ifconfig ppp0\r" | |
expect -re {ip=(\d+\.\d+\.\d+\.\d+)} | |
set ip $expect_out(1,string) | |
expect "net> " | |
send "exit\r" | |
return $ip | |
} | |
set user "julio" | |
set pass [lindex $argv 0] | |
set host "192.168.1.1" | |
set port "2255" | |
send_user "([exec date])\n" | |
spawn ssh -q -o StrictHostKeyChecking=no -p $port $user@$host | |
expect { | |
timeout { send_user "\nFailed to get password prompt\n"; exit 1 } | |
eof { send_user "\nSSH failure for $host\n"; exit 1 } | |
"*assword" { send "$pass\r" } | |
} | |
expect { | |
timeout { send_user "\nLogin failed.\n"; exit 1} | |
"OpenRG> " | |
} | |
send_user "Old IP: \'[get_ip]\'\n" | |
expect "OpenRG> " | |
send "conf\r" | |
expect "conf> " | |
send "set /dev/ppp0/enabled 0\r" | |
expect "conf> " | |
send "reconf 1\r" | |
expect "conf> " | |
send "set /dev/ppp0/enabled 1\r" | |
expect "conf> " | |
send "reconf 1\r" | |
expect "conf> " | |
send "exit\r" | |
expect "OpenRG> " | |
sleep 15 | |
send_user "New IP: \'[get_ip]\'\n" | |
expect "OpenRG> " | |
send "exit\r" | |
close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment