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.

I need to get my router's public IP but due to unreliable Internet connection I can not use web services like http://automation.whatismyip.com/n09230945.asp (this approach fails in most cases). Is there a way to get my public IP directly from my router (or maybe another way to get it without using Internet connection)? Any links are appreciated.

Updated: I have java client/server application with the server part in my home PC and the client part in my phone. My home PC's public IP is dynamic so I periodically need to get my new IP. When my server's IP is changed it can tell it the client part.

share|improve this question

migrated from stackoverflow.com Oct 13 '11 at 23:44

This question came from our site for professional and enthusiast programmers.

1  
In theory you should be able to get it directly from the router, but how you do it depends on the specific model of the router. There's not standard interface for that. –  Aleks G Oct 11 '11 at 15:44
    
you could always visit a site on your server (assuming you have one) then look in your access log –  Johnny Craig Oct 11 '11 at 15:47
    
Your router may not necessarily have a public IP, depends on carrier and location. –  home Oct 11 '11 at 15:47
1  
Maybe use a service like DynDNS. Then your server doesn't need to tell your client its IP. How were you planning to do that anyway? –  jmsu Oct 11 '11 at 16:06
1  
to do what? I already have a way to tell my IP to the client. This is not my question. I'll look forward DynDNS –  Me again Oct 11 '11 at 16:09
show 11 more comments

2 Answers 2

up vote 0 down vote accepted

If you can't use a web service your best bet is to request your router's status page via HTTP and use a regexp to parse the IP from the HTML. You will have to tailor it to the particular router model though. There's no generic way to do it.

share|improve this answer
add comment

Dynamic DNS might be the way to go.

Here is a link to one of the many providers: http://www.zoneedit.com/dynamicDNS.html

Dynamic DNS allows you to give your home network PC or server a permanent address on the Internet. Internet service providers change your IP address on a regular basis, but with Dynamic DNS you can keep your domain pointing at the current IP of your home server or other device.

share|improve this answer
    
+1 for resolving the core issue rather then the perceived problem. –  Miserable Variable Oct 11 '11 at 16:21
add comment

Your Answer

 
discard

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