Advertisement
Frash

Query gateway router for public IP address

Jan 1st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #!/bin/bash
  2. # Author: Frash Pikass
  3. # Dependencies: expect
  4.  
  5. if [ "$#" -eq "3" ]
  6. then
  7.     (expect <<-finish
  8.     #If it all goes pear shaped the script will timeout after 20 seconds.
  9.     set timeout 20
  10.     spawn telnet $1
  11.  
  12.     #The script expects login
  13.     expect "login:"
  14.     #The script sends the user variable
  15.     send "$2\r"
  16.     #The script expects Password
  17.     expect "Password:"
  18.     #The script sends the password variable
  19.     send "$3\r"
  20.     expect "#"
  21.     send "ifconfig ppp0\r"
  22.     expect "#"
  23.     close
  24.    
  25.     finish
  26.     ) | grep -o  'addr:[^ ]*' | sed s/addr://
  27.    
  28.     exit 0
  29.  
  30. else
  31.     echo "Usage: $0 gatewayRouterIP routerAdminUsername routerAdminPassword"
  32.     exit 1
  33. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement