Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

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?
0
riaancornelius
Asked:
riaancornelius
  • 8
  • 5
  • 5
  • +2
3 Solutions
 
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
 
girionisCommented:
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CEHJCommented:
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
 
girionisCommented:
>  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
 
WebstormCommented:
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 5
  • 5
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now