Solved

Changing windows TCP/IP settings from java app.

Posted on 2006-07-07
24
286 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

947 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now