Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to identify router IP address

by dba (Monk)
on Jun 22, 2004 at 13:21 UTC ( #368705=perlquestion: print w/ replies, xml ) Need Help??
dba has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I have to identify the Netgear router IP address from one of the machines connected within a perl script. The machine IP address will be 192.168.0.x, however I need to know the Internet IP address of the router NIC.
Thanks,
dba

Comment on How to identify router IP address
Re: How to identify router IP address
by Abigail-II (Bishop) on Jun 22, 2004 at 13:39 UTC
    Your best bet will be to call whoever is responsible for configuring the router. See, there's nothing magical about IP addresses that make it a router, *any* machine could be a router. If the machine you are running the script on is connected to the same network as the router you are interested in is, its routing table might list it. But maybe it doesn't. Maybe you can run a router discovery protocol. But maybe you can't. It all depends on the network policies. So contact the person or people responsible for setting up the router and/or network. They should know. We don't. All we can say is that 0 < x <= 255.

    Abigail

      Apologize if I was not clear. This is my home Netgear MR814 4 port router. The internet IP changes (almost) everytime when I reboot the router.
        might it suggest DynDNS it allows you to dynamically update a hostname... ala soandso.rules.net so you can always connect to that hostname.. but the true ip behind it is updated via the DynDNS plugin whenever the router DHCP's. You might also want to upgrade the (assuming this is coming from your home cable or dsl connection) your account to have a static IP. ( I don't know if DynDNS can correctly determine the true outgoing ip address being used... because the machine connected to the router should be something like 192.168.1.101..but if the cable modem goes directly into the machine via ethernet port it should work fine
        so you would need something like DynDNS

        I'll suggest something other than DynDNS, and actually use Perl in the process. I keep an external web server with this simple CGI:

        #!/usr/bin/perl use CGI 'header'; print header('text/plain'); print $ENV{REMOTE_ADDR};

        Then you can query that CGI from inside your network and get the IP address. That information is stored on the router itself, of course, but it isn't necessarily easy to get at automatically.

        ----
        send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

        A bit of clicking using the Netgear website reveales that the router has a web interface. I'd expect the configured address can be grabbed from your routers website. Did you check?

        Abigail (bless my ISP who provides me with a static IP address)

Re: How to identify router IP address
by valdez (Monsignor) on Jun 22, 2004 at 14:03 UTC
Re: How to identify router IP address
by neniro (Priest) on Jun 22, 2004 at 14:06 UTC
    Assuming that you're using a win32-box you can simply use tracert for this job. The IP after your routers internal IP should be the one you're looking for.
      I don't believe that's the case. I don't see my actual ip when I tracert perlmonks from a command prompt. it shows the local address of my router.. then the next hop is another box out side our network.
        Yeah, thats true. Seems that this doesn't count as a hop. Odd behavior in my opinion.

        Update:NAT'ing isn't routing - so it can't be a hop. Or am I wrong?

Re: How to identify router IP address
by davido (Archbishop) on Jun 22, 2004 at 15:29 UTC

    One simple solution is to hit one of those websites that reflects your IP address. It's easy for an external website to see what IP is doing an HTTP request, especially if you're not doing anything funky to hide your router's IP.

    In Broadband Dynamic IP Poster I have a series of small scripts that can be used to post your current IP to a remote site so that you can find your IP from somewhere on the outside world. But one of those scripts sets up an IP reflector, which is all you would need to find your IP from within your network. Take a look at that node, and it should be helpful to you.

    You could also scrape the web-interface to your router, however, if your router is like mine, it's heavily Javascript-laden, making it a little tricky to scrape. That's why in Broadband Dynamic IP Poster I chose the reflector site method.


    Dave

      Thank you monks for your replies.
      I will go with 'http://checkip.dyndns.org'
       perl -MLWP::Simple -e "getprint 'http://checkip.dyndns.org'" is neat.

      I get  <html><head><title>Current IP Check</title></head><body>Current IP Address: 24.x.x.x</body></html>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://368705]
Approved by jlk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-09-21 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls