Customers With Disabilities
quick menu

How to get router's IP Address programmatically?

How to get router's IP Address programmatically?

SOLVED
Reply
MikeMike
Contributor
Message 1 of 12
(81,106 Views)

 

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

 

 

11 REPLIES
pamcphilly
Copper Contributor
Message 2 of 12
(81,090 Views)

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.

MikeMike
Contributor
Message 3 of 12
(81,063 Views)

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
Message 4 of 12
(80,916 Views)

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 II
Gold Contributor II
Device: iMac / iMac / iPhone
Plan: Preferred HD 75/75
Location: South Central, PA
Message 5 of 12
(80,811 Views)

The following will also work on a Windows box:

 

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

 

 

FSC
Copper Contributor
Message 6 of 12
(80,633 Views)

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

Silver Contributor IV
Message 7 of 12
(80,606 Views)

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
Message 8 of 12
(80,580 Views)

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();
                }
        }
    }

}

 

 

lucastheisen
Contributor
Message 9 of 12
(63,031 Views)

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" );
Gold Contributor II
Gold Contributor II
Device: Chromecast Roku TV
Plan: Digital Voice, 75/75
Location: Westford MA
Message 10 of 12
(62,975 Views)

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.

 

My Rewards+
Start earning points Enrolling in My Rewards+ is quick, free and easy

Refer A Friend
Refer friends to the Verizon Fios Family, and earn 10,000 My Rewards+ points
Verizon Troubleshooters
Unable to find your answer here? Try searching Verizon Troubleshooters for more options.
 

My Verizon

  • Check Email
  • Add or Change Services
  • Suspend My Service
  • Manage Services
  • Apps

Support

Watch Fios