Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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.

Replies are listed 'Best First'.
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 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.


      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 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 if the cable modem goes directly into the machine via ethernet port it should work fine

        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)

        so you would need something like DynDNS
Re: How to identify router IP address
by davido (Cardinal) 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.


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

      I get  <html><head><title>Current IP Check</title></head><body>Current IP Address: 24.x.x.x</body></html>
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?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2021-09-20 06:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found