views:

227

answers:

2

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.

+1  A: 

Modify windows registry with Java. These links should help you.

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

http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java

Adi
But surely, the modifications will only take affect at the next reboot. I think the OP wants the change to take place sooner.
Stephen C
Wery interesting, I thought about changing registry, but I thought that it will be much more complicated. JRegistry looks very nice.
pnemec
While this is also feasable way how to do that I hoped there is some better way, so I did not mark is at accepted answere.
pnemec
Stephan, I did not know that you need to reboot to affect changes. I never tried this approach on my own. Thanks for point it out.
Adi
A: 

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.

garzanti
pnemec