#!/usr/bin/expect --

##########################################################
#                                                        #
#     Filename: Fore2Fore1.exp                           #
#     An expect script to move the mobile router from    #
#     One Foreign agent to second                        #
#                                                        #
##########################################################

# set expect timeout value
set timeout 30

# set the prompt that expect uses to know if the other side is waiting 
# for a command

set prompt "(%|#|>|\\$) $" ;
catch {set prompt $env(EXPECT_PROMPT) }

# Telnet into Mobile Router Access Point and change SSID
puts "Telnet into MobielRtr"

# spawn telnet session

set tpid1 [ spawn telnet 100.10.10.150 ]

# send a carriage return

send "\r"

# wait for the prompt

expect ">"

# send selection

sleep 1

send "1"

#sleep 2

expect ">"

sleep 1

send "1"

#sleep 2

expect ">"

sleep 1

send "1"

# wait a while

#sleep 2

# send new SSID

expect ">"

sleep 2

send "fore\r"

sleep 1

# Send escape character twice to return to the main menu

send "\027"

sleep 2

send "\027"


expect ">"
send "8"
expect "?"
send "y"
# Kill the telnet session

exec kill -9 $tpid1

exec route del default gw 100.10.18.22
exec route add default gw 100.10.13.7

# Telnet into router Rack7R7 and configure static route

puts "Telnet into Rack7R2"

set tpid2 [ spawn telnet 100.10.14.2 ]

expect "Password"
send "cisco\r"
expect ">"
send "en\r"
expect "Password"
send "cisco\r"
expect "#"
send "configure terminal\r"
expect "(config)#"
#send "no ip route 100.10.10.8 255.255.255.255 fa1/0\r"
#expect "(config)#"
send "ip route 100.10.18.8 255.255.255.255 fastethernet0/0\r"
expect "#"
send "end\r"
expect "#"
send "exit\r"
exec kill -9 $tpid2

# Telnet into Rack6R7 and configure static route

puts "Telnet into Rack6R7"
set tpid3 [ spawn telnet 100.10.13.77 ]
expect "Password"
send "cisco\r"
expect ">"
send "en\r"
expect "Password"
send "cisco\r"
expect "#"
send "configure terminal\r"
expect "(config)#"
send "no ip route 100.10.18.8 255.255.255.255 fa0/1\r"
expect "#"
send "ip route 100.10.18.8 255.255.255.255 fastethernet1/0\r"
expect "#"
send "end\r"
expect "#"
# send "exit\r"
exec kill -9 $tpid3

# Telnet into Rack6R1 and set static route

puts "Telnet into Rack6R1"
set tpid4 [ spawn telnet 100.10.16.11 ]
expect "Password"
send "cisco\r"
expect ">"
send "en\r"
expect "Password"
send "cisco\r"
expect "#"
send "configure terminal\r"
expect "(config)#"
send "no ip route 100.10.18.8 255.255.255.255 ethernet0/0\r"
expect "#"
#send "access-list 1 deny host 100.10.18.8\r"
#expect "#"
#send "access-list 1 permit any\r"
#expect "#"
#send "router rip\r"
#expect "#"
#send "distr 1 out rip\r"
#expect "#"
send "end\r"
expect "#"
exec kill -9 $tpid4

exec route del default gw 100.10.13.7
exec route add default gw 100.10.18.22

    Source: geocities.com/shezy22/cisco_mip/mipconfig3

               ( geocities.com/shezy22/cisco_mip)                   ( geocities.com/shezy22)