Skip to content

Instantly share code, notes, and snippets.

@maxandersen
Created June 30, 2014 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxandersen/dcb662f257b9fd6676d7 to your computer and use it in GitHub Desktop.
Save maxandersen/dcb662f257b9fd6676d7 to your computer and use it in GitHub Desktop.
How to script portforwarding for Swisscom routers.
#!/usr/bin/expect
# <scriptname> <router> <routerusername> <routerpassword> <host>
set timeout 20; #If it all goes pear shaped the script will timeout after 20 seconds.
set router [lindex $argv 0]; # First argument is router (192.168.1.1)
set user [lindex $argv 1]; # Second argument is user (admin)
set password [lindex $argv 2]; # Third argument is password (secret)
set nas [lindex $argv 3]; # Second argument is your NAS you which to forward ports to
spawn telnet $router; # This spawns the telnet program and connects it to the variable name
expect "Login: ";
send "$user\r";
expect "Password:";
send "$password\r";
expect "ADB# ";
send "portmap del nas-znc\r";
expect "ADB# ";
send "portmap add nas-znc 8251 $nas 8251 tcp\r";
expect "ADB# ";
send "portmap del nas-http\r";
expect "ADB# ";
send "portmap add nas-http 5000 $nas 5000 tcp\r";
expect "ADB# ";
send "portmap del nas-https\r";
expect "ADB# ";
send "portmap add nas-https 5001 $nas 5001 tcp\r";
expect "ADB# ";
send "save\r";
expect "ADB# ";
send "exit\r";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment