Solved

Changing windows TCP/IP settings from java app.

Posted on 2006-07-07
24
290 Views
Last Modified: 2008-02-01
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
Comment
Question by:riaancornelius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 5
  • +2
24 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 17056566
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
 
LVL 92

Expert Comment

by:objects
ID: 17056570
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
 
LVL 35

Expert Comment

by:girionis
ID: 17056573
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 150 total points
ID: 17056574
You're going to need registry setting code to do that?

http://www.winguides.com/registry/display.php/269/
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17056576
I was hoping there'd be some library that would hide the native code from me :)
0
 
LVL 35

Expert Comment

by:girionis
ID: 17056582
You can use the library in my link and then write a wrapper that calls it.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17056588
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17056590
CEHJ, That would make it simple to create IP Changing part. thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17056592
Be careful - you might need to reboot the box too
0
 
LVL 92

Expert Comment

by:objects
ID: 17056602
changing the registry is the easy part, lots of libs around for doing that :)

0
 
LVL 92

Expert Comment

by:objects
ID: 17056606
to reboot, use exec() to run:

rundll32.exe shell32.dll,SHExitWindowsEx 2
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17056611
>> 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
 
LVL 9

Author Comment

by:riaancornelius
ID: 17056614
>> to reboot, use exec() to run:
>> rundll32.exe shell32.dll,SHExitWindowsEx 2

I was really hoping rebooting wouldn't be necessary...
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 150 total points
ID: 17056617
>  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
 
LVL 86

Expert Comment

by:CEHJ
ID: 17056623
>>I was really hoping rebooting wouldn't be necessary...

It may not be, but wouldn't surprise me
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17056624
>> Since you will go with CEHJ's suggestion you can have a look here...
Will look at that one too. Thanks
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 200 total points
ID: 17057479
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
 
LVL 13

Expert Comment

by:Webstorm
ID: 17057490
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17057760
thanx webstorm. That's insanely easy :) Pity it's only from WIN2K...
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17120678
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
 
LVL 35

Expert Comment

by:girionis
ID: 17120746
:)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17121200
:-)
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 17121362
:-)
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17121389
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question