6

I've been browsing a lot of questions somehow similar to mine: People want to know with 100% certainty their external IP Address (the one my ISP assigns to me when I ask for an internet connection). Well, the most concrete answer to those questions is: You cannot know your own internet IP address, unless you ask some web service.

How come my router does know that? I'd expect it got it from the ISP itself, and got it "written down".

So, my question is: Is there an universal, standardized way among all routers to ask them to hand me over that piece of information (i.e. my IP Address as signed by my ISP)? I don't mind even if it involves COM interoperability or something to call on unmanaged code.

To elaborate: I want a way to retrieve the IP address assigned to me by my ISP that is 100% accurate, meaning I just want that one address; not a list of addresses for other interfaces or anything else. I find it really hard to believe it's impossible to achieve this.

Edit: I'm sorry but that other question has nothing to do with what I asked. I was asking if routers had some kind of standard API for querying it for it's public IP. I don't see how any of those answers is an answer to my question.


Solved: There is such standard. It's a UPnP standard called WANIPConnection. It has an "action" called GetExternalIPAddress. It seems REALLY difficult to use from a C# program though. But I'm editing my question just so anyone reading it in the future will know the answer to it is YES. Here's a link to the UPnP Forum http://www.upnp.org/ in case anyone wants to pursue this any further. There's also this Open Source project http://opentools.homeip.net/dev-tools-for-upnp. This last project has a lot little softwares (tools), and all it's source code (written in C or C++) is available. I couldn't figure out how to solve my problem because I'm not that smart, but again, if anyone would like to pursue this any further, that DevToolsForUPnP project is another thing to check out.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user2212990
  • 177
  • 1
  • 9
  • 4
    possible duplicate of [Getting my public IP via API](http://stackoverflow.com/questions/3097589/getting-my-public-ip-via-api) – Pierre-Alain Vigeant Jul 18 '13 at 17:24
  • "padronized"? Do you mean "standardized"? [Google Translate](http://translate.google.com/#pt/en/padronizado) says "yes". – John Saunders Jul 18 '13 at 17:24
  • 3
    Dupicate? http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c – shmuelpro Jul 18 '13 at 17:25
  • 3
    yes, all those questions are similar. The point is, my machine knows my router and it's IP address, that's a fact. Another fact is that my router knows my external IP address given to me by my ISP. My question is: can I ASK my router (in some kind of router standarized API, so it would work with any router) what that external IP is? – user2212990 Jul 18 '13 at 17:33
  • 1
    This question is not duplicate. He's not simply asking "how to get the ip using any means at all". He restricted the possible solutions. – usr Jul 18 '13 at 17:40
  • I don't think I'm making myself clear and I'm sorry about that. Let me give you an example found in another question (Assuming DNS class is a way to talk to my router by acessing some sort of standarized routers API): `string host = Dns.GetHostName();` `IPHostEntry ip = Dns.GetHostEntry(host);` `IPAdress myInternetIP = ip.AddressList[0];` Will `myInternetIP` always be my external IP adress, with no exceptions ever? Meaning, will this code always give the external IP address of any machine it runs on? – user2212990 Jul 18 '13 at 17:45
  • You could try pulling down the management page and parsing out the IP address, lots of overhead and quite inefficient (if it works at all). – Pete Garafano Jul 18 '13 at 17:49
  • @TheGreatCO I don't think that would work, because each router has it's own different page. I just wanted to know if there's a way to ask any router in the world "hey what's the internet IP Address you got?" – user2212990 Jul 18 '13 at 17:57
  • @user2212990 not that i've ever heard of. – Pete Garafano Jul 18 '13 at 17:57
  • @user2212990 the code you posted doesn't give the public ip you want, in fact in my case it gives the ip of the virtual adapter of VirtualBox. Also note that not all installations are alike, in my case I am behind two routers, so even if you get the external ip of the first, that would be a private address. – Theraot Jul 18 '13 at 18:03
  • Your router would need an api for you to query (if you want the router to give you the answer). This would be vendor specific. There is no general networking protocol that I know of to get your internet facing IP. There are, however, as other people have mentioned, public services that provide APIs to tell you what IP address your query came from. – Randy James Jul 18 '13 at 18:52
  • Thanks, that settles it for me. Unfortunately, those public services are not that reliablee. No one can be sure they'll still be up and running at any given moment, or they even might stop working at all.. I was just looking for a permanent solution for this and I thought some sort of router stardard API would do the job perfectly. It's a shame there is none. Thanks everyone. – user2212990 Jul 18 '13 at 19:30
  • 2
    One thing you could do, if you don't want to trust someone else's public site or API, is build one of your own and put it out there somewhere on the internet. It would be trivial in any language to do, and you can probably find free (or ridiculously cheap) hosting to put it. Or of course you could find 4 or 5 public ones, so that way when one of them dies off, you'll just hit another one. – Joe Enos Jul 18 '13 at 21:49
  • An ugly hack just occured to me: You could modify your router firmware to map a dns address to your external IP. Or something I did a few years ago: set up a dynamic dns account for your router to update and use that address where you need the external IP. – confusopoly Jul 18 '13 at 22:10
  • Just for closure's sake: I'm going with Joe Enos suggestion and been using Mono.Nat: [link](http://www.fluxbytes.com/tag/mono-nat/). It's nice and simple, and it easily does what I wanted regarding external IP. I can't make any of the rest the library work though, but then again, I'm a self taught 14 years old beginer. The library seems nice though. – user2212990 Aug 01 '13 at 11:06
  • 3
    @user2212990 You should add your solution as an answer and mark it as correct. *[SOLVED]* does not work for StackOverflow engine – Andre Calil Aug 06 '13 at 18:35
  • Also, edit your question to say you're trying to get the router's WAN IP (which may or may not be publicly routable, depending on how many NAT layers are between you and the internet). That incidentally excludes solutions involving `whatismyip.org` and the like. – Ben Voigt Aug 06 '13 at 20:59
  • @Andre Calil Sorry I didn't know that. But I dont quite have the solution, just know it is possible. What should I do please? – user2212990 Aug 06 '13 at 21:13
  • @Ben Voigt I didn't want to add that extra complexity. I was just talking about my own domestic network with one modem, one router and my computer among others. But I think the title is clear about what I'm asking: if there is a standard way to request a router's external IP (which isn't necessarily public). That already excludes whatismyip.org in my opinion. But I agree I'm really bad at asking clear questions I suppose. – user2212990 Aug 06 '13 at 21:14

0 Answers0