0

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.

  • 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. –  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 –  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
  • the thing is my "server" is a java application on my local PC with dynamic IP –  Oct 11 '11 at 15:48
  • why do you need your router's external IP? – Miserable Variable Oct 11 '11 at 15:50
  • @home I can see public IP in the options of my router (192.168.1.1), so it surely has public IP –  Oct 11 '11 at 15:51
  • Hm, this is definitly not your public IP. It's a private IP address space, maybe this is your internal network - e.g. the address to which your router listens in your private LAN. See this: http://en.wikipedia.org/wiki/192.168 – home Oct 11 '11 at 15:52
  • @HemalPandya In two words - I have dynamic IP and I have to know it to connect to my pc with a mobile –  Oct 11 '11 at 15:53
  • @home It says: IP Address: 178.120.61.63 and this is exactly what automation.whatismyip.com returns. You got me wrong: 192.168.1.1 is how I access my router –  Oct 11 '11 at 15:54
  • @Me again: Maybe you should tell us what you try to achieve. – home Oct 11 '11 at 15:55
  • Ok, looks like you're somewhere in Belarus and your provider seems to be BELTELECOM, but I can't _tracepath_ you. Looks like you're behind a firewall?! – home Oct 11 '11 at 16:03
  • @home most of what you've said is true but I don't see how this helps –  Oct 11 '11 at 16:05
  • 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? –  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 –  Oct 11 '11 at 16:09
  • If the question is being able to connect to a dynamically assigned IP then the correct answer is DynDNS. – Miserable Variable Oct 11 '11 at 16:20
  • @Me again: This was not an offense, I just provided some facts - that's why it was just a comment :-) – home Oct 11 '11 at 16:23

2 Answers2

2

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.

NPE
  • 679
  • 3
  • 10
  • 20
0

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.

Boann
  • 148
  • 8