Thursday, October 15, 2009

Java Source Code to find the IP Address of the machine

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

public class ipfind {

ipfind(){

try{
Enumeration e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements()){
NetworkInterface ni = (NetworkInterface)e.nextElement();
Enumeration e1 = ni.getInetAddresses();
while(e1.hasMoreElements()){
InetAddress inetAddress = (InetAddress)e1.nextElement();
System.out.println(" " + inetAddress.getHostAddress());
}

}
}catch(Exception e){

}
}

public static void main(String args[]){
ipfind ipf = new ipfind();
}
}

No comments:

Total Pageviews