Changing windows TCP/IP settings from java app.

Hi all,

I need to create a java app that will automatically change the IP Address and gateway of a windows machine based on the time of day.
If at all possible, the app should also contain code to limit the bandwidth usage through a specific network card(or all bandwidth usage if that isn't possible)

I don't need help with the apps logic, but I have no idea where to start for changing the TCP/IP settings, and even less of a clue regarding the bandwidth limiting...

Any ideas?
LVL 9
riaancorneliusAsked:
Who is Participating?
 
WebstormConnect With a Mentor Commented:
Hi riaancornelius,

You can call netsh program:

Runtime.getRuntime.exec(new String[]{
      "netsh",  // C:\WINNT\system32\netsh.exe
      "interface","ip","set","address","Connection name","static",
      "192.168.0.1",      // <-- IP address
      "255.255.255.0",  //  <- network mask
      "192.168.0.254"   // <- gateway
       });
0
 
girionisCommented:
I don't think you can do it with pure java. You will have to resort to jni: http://java.sun.com/j2se/1.4.2/docs/guide/jni/
0
 
objectsCommented:
not really a Java question as you'll need native code to implement it.
So I'd suggest asking in one of the Windows TA's :)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
girionisCommented:
0
 
CEHJConnect With a Mentor Commented:
You're going to need registry setting code to do that?

http://www.winguides.com/registry/display.php/269/
0
 
riaancorneliusAuthor Commented:
I was hoping there'd be some library that would hide the native code from me :)
0
 
girionisCommented:
You can use the library in my link and then write a wrapper that calls it.
0
 
CEHJCommented:
0
 
riaancorneliusAuthor Commented:
CEHJ, That would make it simple to create IP Changing part. thanks.
0
 
CEHJCommented:
Be careful - you might need to reboot the box too
0
 
objectsCommented:
changing the registry is the easy part, lots of libs around for doing that :)

0
 
objectsCommented:
to reboot, use exec() to run:

rundll32.exe shell32.dll,SHExitWindowsEx 2
0
 
riaancorneliusAuthor Commented:
>> changing the registry is the easy part, lots of libs around for doing that :)
Indeed. Sorry Girionis, There's simpler ways of doing it than your link.
0
 
riaancorneliusAuthor Commented:
>> to reboot, use exec() to run:
>> rundll32.exe shell32.dll,SHExitWindowsEx 2

I was really hoping rebooting wouldn't be necessary...
0
 
girionisConnect With a Mentor Commented:
>  Sorry Girionis, There's simpler ways of doing it than your link.

No problem. This is the point fo a forum, people talk and exchange ideas :) I learned something too.

Since you will go with CEHJ's suggestion you can have a look here: http://www.bayequities.com/tech/Products/jreg_key.shtml for another library that reads the registry.
0
 
CEHJCommented:
>>I was really hoping rebooting wouldn't be necessary...

It may not be, but wouldn't surprise me
0
 
riaancorneliusAuthor Commented:
>> Since you will go with CEHJ's suggestion you can have a look here...
Will look at that one too. Thanks
0
 
riaancorneliusAuthor Commented:
thanx webstorm. That's insanely easy :) Pity it's only from WIN2K...
0
 
riaancorneliusAuthor Commented:
Webstorms way really is easiest, but it only works on win2k and later, so I'm also splitting points with CEHJ and Girionis whose solutions will work (with some effort...) on any version of windows.

Hope everybody is happy with this.
0
 
girionisCommented:
:)
0
 
CEHJCommented:
:-)
0
 
WebstormCommented:
:-)
0
 
riaancorneliusAuthor Commented:
:)
0
All Courses

From novice to tech pro — start learning today.