Its very simple ,for the testing you want to import "java.net.InetAddress" package
//Get an instance of InetAddress for the local computer
InetAddress inetAddress = InetAddress.getLocalHost();
//Get a string representation of the ip address
String ipAddress = inetAddress.getHostAddress();
//Print the ip address
System.out.println(ipAddress);
//Get an instance of InetAddress for the local computer
InetAddress inetAddress = InetAddress.getLocalHost();
//Get a string representation of the ip address
String ipAddress = inetAddress.getHostAddress();
//Print the ip address
System.out.println(ipAddress);
Comments
How you will change your local ip address using java?
Does java has any methods to do this?
Please guide me?
Try this java code....
import java.io.IOException;
import java.lang.Runtime;
public class Chang_Ip {
public static void main(String args[]) throws IOException
{
String str1="192.168.0.201";
String str2="255.255.255.0";
String[] command1 = { "netsh", "interface", "ip", "set", "address",
"name=", "Local Area Connection" ,"source=static", "addr=",str1,
"mask=", str2};
Process pp = java.lang.Runtime.getRuntime().exec(command1);
}
}