Results 1 to 3 of 3
Thread: Get Ip adress?
- 04-17-2009, 07:55 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 6
- Rep Power
- 0
- 04-17-2009, 08:08 PM #2
The IP address you get from whatismyip will be the external IP address of your router or equivalent, which has a separate IP address for your local network side. Only external servers can see the external IP, while you can only see the local IP. Try connecting a socket to an external server and asking what your IP is.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 07-11-2009, 02:15 PM #3
Member
- Join Date
- Jul 2009
- Location
- bhubaneswar
- Posts
- 5
- Rep Power
- 0
If u want to know ur own ip address ..the following code may help u...
import java.util.*;
import java.net.*;
import java.net.NetworkInterface;
public class InetAssressExample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces();
if (interfaceList == null)
System.out.println("Error");
else {
while(interfaceList.hasMoreElements()) {
NetworkInterface iface = interfaceList.nextElement();
System.out.println("Interface : " + iface.getName() + " :: ");
Enumeration<InetAddress> addrList = iface.getInetAddresses();
if(!addrList.hasMoreElements()) {
System.out.println("\t(No address for this interface");
}
while(addrList.hasMoreElements()) {
InetAddress address = addrList.nextElement();
System.out.println("\tAddress " + ((address instanceof Inet4Address ? "(v4)"
: (address instanceof Inet6Address ? "(v6)" : "(?)"))));
System.out.println(": " + address.getHostAddress());
}
}
}
}catch(SocketException se) {
System.out.println("Error getting network interfaces : " + se.getMessage());
}
}
}


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks