Sam Adamsh
Sam Adamsh

Reputation: 3391

Use VPN ip address htttp Urlconnection java

I have openVPN Connect configured on a vista laptop, so that connecting with a web browser allows the computer to change its ip address. What are the steps necessary to allow the following networking code in java to use this new ip address:

HttpURLConnection x=(HttpURLConnection)new URL("google.com/search?sclient=psy-
ab&h1=en&site=&source=hp&q=ip%20address&btnG=Search").openConnection(); 

And then open an input stream, read it in, and see one of the vpn addresses in the page, after the html: "Your public IP address is "

Upvotes: 0

Views: 1836

Answers (1)

Dan Hardiker
Dan Hardiker

Reputation: 3053

You can't without calling to an external service.

You will need to have your application call something like http://www.whatismyip.com/ and parse out the IP address the wider internet sees you as. There is probably a REST service you can call which gives you the answer back as XML/JSON/something more computer parseable.

Unfortunately, your local machine does not have enough information for Java to be able to find out without going external.

Upvotes: 1

Related Questions