Java ip address proxy

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 03:23:37

问题


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.x.x) Subnet Mask.....:255.255.224.0 Default Gateway....(some ip different than the ipv4 address above)


回答1:


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 (e.g. 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.



来源:https://stackoverflow.com/questions/8772318/java-ip-address-proxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!