Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Basically I am trying to automate logging into the routers setup config page, and if I can get the default gateway ip I want to be sure that I will be able to use that ip to login to the routers config page (of course assuming router has config page and I have user/pass etc). I am wanting to know that forth purposes I described it will always work, as I am unsure of the definition of the default gateway ip as compared to the ip of the connected router.

Ps: all references to ips I've made are of course internal ips and I am not talking about internet ips.

Edit: also I am trying to up vote you guys for ur very well articulated answers but it wont let me as I don't have 15 points yet ;/ so pls bare with me...

share|improve this question
    
Are you writing code for internal use only (i.e. your network) or will this be deployed to unknown networks? –  gravyface Oct 3 '10 at 22:19
    
hi, this will be deployed on unknown networks... any ideas? thanks –  user55887 Oct 13 '10 at 1:33
add comment

3 Answers

up vote 6 down vote accepted

The "default gateway" is simply the IP of the next hop for traffic that is not explicitly routed anywhere else. This will, almost certainly, be an IP address on an interface of a local router. However, it may not be an address on which you can manage the router.

If this is for a "home-type network", the inside IP (your default gateway) and the management address will probably be one and the same, but in a "large/corporate-type network" I wouldn't be so sure.

share|improve this answer
    
How do I get the management address either in code or using the registry? I know I can always see when I right click on the router item inside windows network link, and it has management page address ip listed, so where is this information stored so i can retrieve it in code? Thank. –  user55887 Oct 1 '10 at 15:14
    
Unless you store your router's management address yourself, it's simply not there to retrieve. But, as I said, the only time it's likely to differ is when you have a network with tens, hundreds or maybe thousands of routers. –  Vatine Oct 2 '10 at 9:15
    
In other words, if you haven't payed over $1000-2000 for the router, there's little chance you even can have management IP and local IP different. –  Hubert Kario Oct 2 '10 at 13:17
    
Well, I suspect I can make that happen on my 50 quid Zyxel, but I have absolutely no need for it. –  Vatine Oct 3 '10 at 8:19
    
this sounds encouraging, at least for most cases its good news. –  user55887 Oct 13 '10 at 1:34
add comment

I'm going to hit you with the big "Depends": on some networks, the default gateway maybe a Layer 3 switch; you may also find that the default gateway (typically the LAN IP) is not the same interface that the management console/Web GUI listens on.

If you're talking about SOHO/SMB "flat" networks, then yes, the majority of the time the default gateway will also be the router's IP.

share|improve this answer
    
How do I get the management address either in code or using the registry? I know I can always see when I right click on the router item inside windows network link, and it has management page address ip listed, so where is this information stored so i can retrieve it in code? Thank. –  user55887 Oct 1 '10 at 15:16
    
The only Windows product I know that kinda does this is Small Business Server during the network setup wizard, but even that's hit or miss: I've had plenty of firewall/routers that it doesn't detect properly. Long story short: don't waste your time trying to do this programmatically unless you have complete control over the environment that you're implementing this code in. –  gravyface Oct 1 '10 at 15:27
    
check this out .... described what im thinking perfectly... stackoverflow.com/questions/3839189/… –  user55887 Oct 1 '10 at 15:38
    
basically, the information is there, must be a way to retreive it... i have complete control of the environment... + admin rights :) –  user55887 Oct 1 '10 at 15:39
    
gravyface was thinking about the whole network, not just your computer. And looking for management interfaces in different places than default gateway is highly heuristic. I highly doubt that Windows can detect routers not being default gateways. –  Hubert Kario Oct 2 '10 at 13:21
add comment

To get the default gateway parse the output of the "route print -4" command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.