deve-lopez
asked on
Retrieving local IP assigned from VPN DHCP
Hi,
My computer is connected to Internet via a Router.
The Router is connected to my ISP.
I connect to an Office WAN via a VPN connection.
Using Java code:
I need to retrieve the Dynamic IP address assigned to my computer by the VPN DHCP.
I tried to use the code sample bellow but it returns the LAN IP address.
My knowledge of the package java.net.* is limited.
Any help would be greatly appreciated.
Thanks
My computer is connected to Internet via a Router.
The Router is connected to my ISP.
I connect to an Office WAN via a VPN connection.
Using Java code:
I need to retrieve the Dynamic IP address assigned to my computer by the VPN DHCP.
I tried to use the code sample bellow but it returns the LAN IP address.
My knowledge of the package java.net.* is limited.
Any help would be greatly appreciated.
Thanks
InetAddress address = InetAddress.getLocalHost();
System.out.println(address.toString()); // returns 10.0.1.1 (the LAN IP assigned by the router)
You could make a connection to whatismyip.com and read the response
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
whatismyip returns the IP of the web gateway when accessed while on VPN.
I found the method to obtain all the IPs assigned.
I just have to pick the good one from the list.
Attached is the code for anyone who is interested.
Thanks
I found the method to obtain all the IPs assigned.
I just have to pick the good one from the list.
Attached is the code for anyone who is interested.
Thanks
public static void main(String[] args) {
// TODO code application logic here
try {
//InetAddress address = InetAddress.getLocalHost();
//InetAddress address = InetAddress.getByName("lvignals-us64.us.oracle.com");
InetAddress address[] = InetAddress.getAllByName("lvignals-us64.us.oracle.com");
for (int i=0; i<address.length; i++) {
System.out.println(address[i].toString());
}
} catch (UnknownHostException e) {
System.out.println("LVI: Could not determine this computer address..."+e.toString());
}
}
> Actually http://www.whatismyip.com/automation/n09230945.asp
you don't need to do that, and it won't return what you want anyway
you don't need to do that, and it won't return what you want anyway
> InetAddress address[] = InetAddress.getAllByName(" lvignals-u s64.us.ora cle.com");
you don't need to know the hostname, see the code I posted above
you don't need to know the hostname, see the code I posted above
>>whatismyip returns the IP of the web gateway when accessed while on VPN.
Yes, that's usually what you need
Yes, that's usually what you need
ASKER
In this case what was needed was the IP of the specific laptop running the code when that laptop is connected via VPN:
InetAddress address[] = InetAddress.getAllByName(" machinenam e.domain.c om");
does exactly what is needed, it returns the list of IP used by each active network adapter on the laptop.
InetAddress address[] = InetAddress.getAllByName("
does exactly what is needed, it returns the list of IP used by each active network adapter on the laptop.
what I posted above should provide that, did you try it?
ASKER
Thanks