#!/usr/bin/expect # Author: Adamo Ferro # Version: 1.0 (January 27, 2016) # This script allows the modification of network IP address/netmask # and the global default gateway of a MOXA EDS-405A/408A switch. # The script automatically enters the menus of the MOXA telnet # interface, and writes the new parameters moving between the # form fields. # # Usage: # ./moxa-eds405a-408a-change-network-address # # Requirements: # - Linux machine and shell utility "expect" # "expect" can be easily installed on Ubuntu/Debian systems using: # sudo apt-get install expect # - give execution rights to the script # (e.g. chmod a+x moxa-eds405a-408a-change-network-address) # - IMPORTANT: after changing the network parameters it is possible # that the switch becomes unreachable. # Modifications you may need: # - depending on the speed of your network, you may need to tune # differently the timeout and sleep times # ************** BEGINNING OF THE SCRIPT ************** # PARSING OF INPUT PARAMETERS # current IP address set ip_address_old [lindex $argv 0] # new network parameters set ip_address [lindex $argv 1] set netmask [lindex $argv 2] set default_gateway [lindex $argv 3] # password set password [lindex $argv 4] # tune to the slowest operation set timeout 2 # connect via telnet to current IP spawn telnet $ip_address_old # expect password request expect ": 1" { send "\n" expect "Password :" { # send "down arrow" and password send "\033\[B" send "$password\n" # select the first option of the menu: "Basic Settings" expect "select. -" send "\n" # select the "Network" tab expect "Basic Settings" send "n\n" # select the first option: "IPSettings" expect "Neighbor Cache" send "\n" # fill network parameters fields expect "Link-Local Address" send "\033\[B" send "$ip_address " send "\033\[B" send "$netmask " send "\033\[B" send "$default_gateway " # exit (with ESC) and confirm modifications send "\033" expect "Neighbor Cache" send "\033" expect "(Y/N)" send "y" expect "(Y/N)" send "y" sleep 1 # ----- CONNECTION IS LOST ----- } }