简体   繁体   中英

Java ip address proxy

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:

  import java.net.*;

  public class A
 {
    public static void main(String[] args)throws Exception
    {
       InetAddress kj=InetAddress.getLocalHost();
       System.out.println(kj.getHostAddress());


     }

 }

running ipconfig from command prompt: Ethernet adapter Local Area Connection 2:

connection-specific dns suffix : Link-local IPv6 Addres....:fe80::adde(ect...) IPv4 Address........(5.5.32.x) Subnet Mask....(255.255.0.0) Default Gateway.....:

Ethernet adapter Local Area Connection: Connection-specific DNS suffic .: (ect...) Link-local IPv6 Address ...: fe80::8177:a91b:(ec...) IPv4 Address......:(76.181.xx) Subnet Mask.....:255.255.224.0 Default Gateway....(some ip different than the ipv4 address above)

You can get all the IP addresses of the local machine this way:

String hostName = InetAddress.getLocalHost().getHostName();
InetAddress addrs[] = InetAddress.getAllByName(hostName);

You will need a way of determining which of the IP addresses are for the VPN. Typically a VPN will give you a known range of addresses (eg 10.19.10.x) which you can detect.

If you connect to the VPN, then from a command line run ipconfig , pasting the output here, we may be able to help you determine the pattern to match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM