• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to get the real ip? (gateway ip instead of machine ip)

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to get my real ip because that ip is for server use (http://ip:8080/...), I tried:
InetAddress local = InetAddress.getLocalHost();
System.out.println(local.getHostAddress());
}catch (java.net.UnknownHostException e){}
But it gives me my machine ip instead of real ip, using http://machineip/... people can't reach my comp. So please would anyone know how can I get my real ip?Thanks!
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to stick an "I don't know what I'm talking about" sticker on this reply.
Would it be possible for you to do something fancy like connect to another machine and have it tell you your IP address?
Maybe the dnsjava implementation can do it properly (something like "org.xbill.DNS.dns.inaddrString(InetAddress.getLocalHost())").
You could also try plain old InetAddress.getAddress() just in case it wants to be cool.
[ April 07, 2002: Message edited by: David Weitzman ]
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the question you've asked is really :
How do I know what address I am presenting to the Internet, rather than my own machine IP.
If this is because you are, as people have mentioned, behind a firewall, and your machine IP is in a private addressing range (10.x.x.x, 192.168.x.x etc), and are using NAT to connect to the outside world through a router/firewall. The answer is you can't really do this programatically thru java...
What you can do is to setup ip filtering on your firewall/router such that all inbound packets from the internet to xyz.acme.com:8080 are passed to your machine.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic