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.

链接地址: http://www.djcxy.com/p/65796.html

上一篇: 使用Java客户端API连接到Cloudera VM上的Hbase:

下一篇: Java的IP地址代理