Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to get my router's public IP but due to unreliable Internet connection I can not use web services like (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 Oct 13 '11 at 23:44

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

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
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
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
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

Dynamic DNS might be the way to go.

Here is a link to one of the many providers:

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

Your Answer


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