Customers With Disabilities
  • RESIDENTIAL
  • BUSINESS

    Verizon Business Sites

  • WIRELESS
Reply
Contributor
MikeMike
Posts: 2
Registered: ‎10-11-2010
0 Kudos
Accepted Solution

How to get router's IP Address programmatically?

 

While on my computer, behind the router Verizon router, I need to know my the router's IP address, so I can ssh into my box from remote hosts.

 

When I subscribed to cable, and had a Linksys router as my main gateway at 192.168.1.1, I could log into it programmatically (using Perl LWP) and parse out the WAN IP address.

 

But with the ridiculous Verizon setup, their login screen is jam-packed with silly Javascript that changes the number of characters on the screen as you type, etc (all of which have been covered in these forums), and I cannot figure out what the heck it is doing.  Logging into the router manually works fine.  But I need to be able to do so programmatically.

(Or is there some other way to obtain my router's WAN IP address from my local system?)

 

Any suggestions?

 

Thanks,

 

-Mike

 

 

Copper Contributor
pamcphilly
Posts: 26
Registered: ‎05-29-2009

Re: How to get router's IP Address programmatically?

Couldn't you just setup a dynamic dns name from dyndns.org (or one of the other providers) and set that up in the router's dynamic dns setup.  That way you could always use a FQDN instead of an ip address.  The router will also keey dyndns.org updated with you curring WAN ipaddress.

 

If you want to do something progamatically you could access a website like http://www.whatsmyip.org/ and parse its response.

Contributor
MikeMike
Posts: 2
Registered: ‎10-11-2010
0 Kudos

Re: How to get router's IP Address programmatically?

HA!  Such simple solutions, thanks.

 

I've been so focused (with tunnelvision) on the way I'd been doing it before that I never considered these possibilities.  Thanks for the kick in the butt.  I needed it.

 

-Mike

 

 

Silver Contributor IV
Anti-Phish
Posts: 1,089
Registered: ‎12-04-2009

Re: How to get router's IP Address programmatically?


MikeMike wrote:

 

When I subscribed to cable, and had a Linksys router as my main gateway at 192.168.1.1, I could log into it programmatically (using Perl LWP) and parse out the WAN IP address. 


 

You can also telnet into the router and use the command line interface.

 

Telnet 192.168.2.1

User: admin

Password: *******

Wireless Broadband Router> rg_conf_print /dev/ixp0/dyn
(dyn
  (ip(192.168.1.4))
)

Returned 0
Wireless Broadband Router>

 

* 192.168.2.1 is the LAN address of my test router

   192.168.1.4 is the WAN address of my test router.

 

Gold Contributor I
lasagna
Posts: 1,788
Registered: ‎05-27-2010
Plan: Prime HD 50/25
Location: South Central, PA

Re: How to get router's IP Address programmatically?

The following will also work on a Windows box:

 

nslookup -type=a myip.opendns.com resolver1.opendns.com

 

 

FSC
Copper Contributor
FSC
Posts: 39
Registered: ‎10-13-2010
0 Kudos

Re: How to get router's IP Address programmatically?

login to the router it tells you the ip addresses connected to the device.

Silver Contributor IV
Anti-Phish
Posts: 1,089
Registered: ‎12-04-2009
0 Kudos

Re: How to get router's IP Address programmatically?


FSC wrote:

login to the router it tells you the ip addresses connected to the device.


Did you read the OP's post?

He wants to determine the WAN IP address programmatically.

 

 

FSC
Copper Contributor
FSC
Posts: 39
Registered: ‎10-13-2010

Re: How to get router's IP Address programmatically?

[ Edited ]

Dint someone answer the question to that...above...

I thought I wanted to give some extra info.

 

In Java:

 

 

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/**
 *
 * @author tntadmin
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         BufferedReader buffer = null;
        try {
                URL url = new URL("http://whatismyip.com/automation/n09230945.asp");
                InputStreamReader in = new InputStreamReader(url.openStream());
                buffer = new BufferedReader(in);

                String line = buffer.readLine();
                System.out.println(line);
        } catch (IOException e) {
                e.printStackTrace();
        } finally {
                try {
                        if (buffer != null) {
                                buffer.close();
                        }
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }
    }

}

 

 

Contributor
lucastheisen
Posts: 2
Registered: ‎07-13-2013
0 Kudos

Re: How to get router's IP Address programmatically?

Thats great information, but on my router I had to enable telnet first through: Advanced->Local Administration

Given that its telnet, I had to pair it with Expect, and since the original post asks about perl, here is what I did:

#!/usr/bin/perl

use strict;
use warnings;

use Expect;

my $username = '';
my $password = '';
my $command = 'conf print /dev/eth1/dyn/ip/';

my $exp = Expect->new();
$exp->raw_pty( 1 );
$exp->log_stdout( 0 );
$exp->spawn( 'telnet 192.168.1.1' );
$exp->expect( 10, 'Username' );
$exp->send( "$username\n" );
$exp->expect( 10, 'Password' );
$exp->send( "$password\n" );
$exp->expect( 10, 'Wireless Broadband Router>' );
$exp->send( "$command\n" );
my ($matchedPatternPosition, $error, $successfullyMatchingString, $beforeMatch, $afterMatch) = $exp->expect( 10, '-re', '\(ip\(.*?\)\)' );
$exp->expect( 10, 'Wireless Broadband Router>' );
$exp->send( "exit\n" );
$exp->hard_close();

my $ip;
if ( $successfullyMatchingString =~ /\(ip\((.*?)\)\)/ ) {
    $ip = $1;
}

print( "ip is $ip\n" );
print( "DONE\n" );
All Star
viafax999
Posts: 1,713
Registered: ‎11-10-2009
Device: Chromecast tv phone
Plan: Digital Voice, 75/35
Location: Westford MA
0 Kudos

Re: How to get router's IP Address programmatically?


MikeMike wrote:

HA!  Such simple solutions, thanks.

 

I've been so focused (with tunnelvision) on the way I'd been doing it before that I never considered these possibilities.  Thanks for the kick in the butt.  I needed it.

 

-Mike

 

 


Be aware that dyndns now requires that users with free accounts need to logon to the account every 30 days else the account will be deleted.

Not that onerous but a PIA

I just set up a schedules task to kick up the logon screen every couple of weeks.

 

 

Account & Services

  • Pay Bill
  • Add/Change Services
  • Manage My Rewards+
  • Renew Your Contract
  • Manage Services
  • Visual 411

Email, News & TV

  • Check Email
  • Announcements

Support Tools