从 java 设置 Windows XP 网络接口的 ip 地址
我需要通过我们的 Java APP 在 Windows XP 机器上设置 IP 地址。由于我不知道如何纯粹从java设置它,我想使用 netsh 来设置它。然而,由于有多个接口,我需要获得网络连接的特殊“长名称”。
Nethsh 命令将如下所示:
netsh interface ip set address name="Local Area Connection" source=dhcp
我尝试使用
NetworkInterfaceclass to obtain it, but without success. For network name on Windows xp it return names like "eth0" :)
我目前正在解析命令“ipconfig”的输出,但这不仅是有问题的,而且它也不能随着各种 XP 语言突变而扩展。
I need to set IP adress on Windows XP machine from our Java APP. As I do not know any way how to set it purely from java I would like to use netsh to set it. Howerver as there are more than one interfaces I need to obtain special "long name" of network connection.
Nethsh command will look like this:
netsh interface ip set address name="Local Area Connection" source=dhcp
I tried to use
NetworkInterface
class to obtain it, but without success. For network name on Windows xp it return names like "eth0" :)
I am currently parsing output of command "ipconfig", but not only it is problematic, it also do not scale with various XP language mutations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用Java修改Windows注册表。这些链接应该对您有帮助。
http://www.windowsreference.com/networking/ dhcp-static-ip-settings-in-windows-registry
读取/使用 Java 写入 Windows 注册表
Modify windows registry with Java. These links should help you.
http://www.windowsreference.com/networking/dhcp-static-ip-settings-in-windows-registry
read/write to Windows Registry using Java
尝试使用IPHelper API,你可以在MSDN上找到很多示例和文档。当然,您必须进行本机方法调用。这是 MSDN 上 IP Helper 主页的链接: http://msdn.microsoft.com/en-us/library/aa366073%28v=VS.85%29.aspx
另外,我可以给您一些有关本机 C++ 代码上的托管包装器的 .net 链接,但你在 Java 上工作。
Try using IPHelper API, you can find on MSDN a lot of examples and documentation. Of course you will have to make native method invocation. This is the link to IP Helper homepage on MSDN: http://msdn.microsoft.com/en-us/library/aa366073%28v=VS.85%29.aspx
Also I could give you a few .net links regarding managed wrappers over native C++ code, but you work on Java.
它对我有用
netsh -c interface ip show config
你会看到接口的长名称
和下一个
netsh interface ip set address "Połączenie lokalne" static 192.168.1.34 255.255.255.0 192.168.1.247 1
M$ 有帮助页面
http://support.microsoft.com/kb/257748/en-us
It works for me
netsh -c interface ip show config
you see long name of the interface
and next
netsh interface ip set address "Połączenie lokalne" static 192.168.1.34 255.255.255.0 192.168.1.247 1
There is help page from M$
http://support.microsoft.com/kb/257748/en-us