开发者

Set ip adress for network interface in Windows XP from java

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 X开发者_Go百科P language mutations.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜