Java 如何更改本地机器/以太网 IP 地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19376215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:34:41  来源:igfitidea点击:

how to change local machine/ethernet ip address

javawindowsvb.netdnsip-address

提问by Ferdie Vianto

I'm trying to make a program that can change pc/laptop ip address & subnet mask. the input I'm trying to make is similar with the interface on IPv4 properties on windows(ip/subnet, dns/alternate dns).

我正在尝试制作一个可以更改个人电脑/笔记本电脑 IP 地址和子网掩码的程序。我尝试进行的输入与 Windows(ip/子网、dns/alternate dns)上 IPv4 属性的接口类似。

the ones that I can think of right now is using a netsh command to change the windows ip. what i want to do is to set/get the ethernet setting on windows

我现在能想到的是使用 netsh 命令来更改 Windows ip。我想要做的是在 Windows 上设置/获取以太网设置

thanks in advance

提前致谢

采纳答案by Ezzored

You can change the registry in JAVA, wich should do the trick. These should help:

您可以在 JAVA 中更改注册表,这应该可以解决问题。这些应该有帮助:

http://www.windowsreference.com/networking/dhcp-static-ip-settings-in-windows-registry/

http://www.windowsreference.com/networking/dhcp-static-ip-settings-in-windows-registry/

http://www.windowsreference.com/networking/dhcp-static-ip-settings-in-windows-registry/

http://www.windowsreference.com/networking/dhcp-static-ip-settings-in-windows-registry/

Other method is to call the netsh command from JAVA:

另一种方法是从 JAVA 调用 netsh 命令:

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