Search code examples
javahttpnat

Inside and Outside NAT with Java


We are writing a HTTP based desktop application whose client runs from outside our NAT. We code and test from inside the NAT. The http server sits within our NAT (yes it is bad network design). What would be the best Java method for automatically detecting where the HTTP client is launching from and passing the appropriate server IP (i.e. NAT internal or External) ?

server_ip = 0.0.0.0
if(inside_nat())
   server_ip = 192.168.0.*
else
   server_ip = 202.13.14.15

Need a java implementation of insider_nat()


Solution

  • We resolved this with a DNS entry in our Windows Small Business server (which is used as a local default DNS). The Java name to IP resolution is used to find the corresponding IP where port mapping is used and internal and external ports differ.