Change Computer IP address using JAVA

Zulkernain Tasin picture Zulkernain Tasin · Oct 7, 2014 · Viewed 11.6k times · Source

I need to change computer IP address using java... I have tried this one but this doesnot work...

    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);

Answer

Alnitak picture Alnitak · Oct 7, 2014

You (probably) need to correctly concatenate those key=value arguments - as written they'll be treated as separate arguments, i.e.

{..., "addr1=" + str1, "mask=" + str2 };