[erlang-questions] Simple NAT traversal

Michael Santos michael.santos@REDACTED
Wed Feb 1 14:47:37 CET 2012


On Wed, Feb 01, 2012 at 12:25:02AM -0800, eigenfunction wrote:
> Hi everybody,
> i have an erlang application running behind a nat. Now i have come to
> a point where i need to know my public ip. I was thinking about
> running a tiny tcp server behind the nat whose sole purpose would be
> to send me my public ip. My question is this: isn't there a more
> simple alternative? Heck, even if i could determine the public ip of
> the NAT device without doing a "backflip" it will be enough for my
> case.
> Any idea?

You could ask a 3rd party service:

1> inets:start().
ok.
2> URL = "http://automation.whatismyip.com/n09230945.asp".
3> {ok, {{"HTTP/1.1",200,"OK"}, _Headers, Body}} = httpc:request(URL).
{ok,{{"HTTP/1.1",200,"OK"},
     [{"cache-control","private"},
      {"date","Wed, 01 Feb 2012 13:15:10 GMT"},
      {"server","Microsoft-IIS/6.0"},
      {"content-length","13"},
      {"content-type","text/html"},
      {"x-powered-by","ASP.NET"},
      {"set-cookie",
       "ASPSESSIONIDQARTQQTD=DEJMEEEANLDPDNGGOJIKKFAG;
       path=/"}],
    "1.11.111.12"}}
4> inet_parse:address(Body).
{ok,{1,11,111,12}}

Google will show you your public IP too:

http://google.com/?q=what+is+my+ip+address




More information about the erlang-questions mailing list