1

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.

pnemec
  • 467
  • 1
  • 5
  • 11
  • 3
    What's the actual higher-level requirement you're trying to solve? There might be a better way to do this; OTOH I wouldn't be too impressed if a Joe Random Application would try to fiddle with the network settings on my machine. – Timo Geusch Feb 17 '10 at 08:09
  • Timo Geusch: Well. Win Xp are hosting our application. We remove Win XP interface (explorer). In case of replacing broken box we need to set original IP adress. DHCP is not available:( – pnemec Feb 17 '10 at 14:42

3 Answers3

1

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

Community
  • 1
  • 1
Adisesha
  • 5,200
  • 1
  • 32
  • 43
  • 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 Feb 17 '10 at 11:47
  • Wery interesting, I thought about changing registry, but I thought that it will be much more complicated. JRegistry looks very nice. – pnemec Feb 17 '10 at 14:40
  • 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 Feb 17 '10 at 14:46
  • 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. – Adisesha Feb 18 '10 at 06:51
0

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
  • 2,162
  • 1
  • 22
  • 30
  • I see this option very simillar to previous two (registry, or external app). I hoped for native support, But it look like this is not task for java. By the way extranl app (ipconfing & netsh) works just fine. – pnemec Jul 03 '10 at 16:27
0

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

Zbigi
  • 1
  • 1
    This is not answerer to my question. I know that this is working. but I would like to obtain long name from Java, differently than calling external netsh command and parse it`s output. – pnemec Dec 29 '10 at 14:55