LSFKing
LSFKing

Reputation: 5

java - Connecting and Disconnecting from networks on windows/linux

I've been searching for an answer to this question but it seems there have only been answers regarding implementing it on Android.

What I'm trying to do is have a Java program that, after meeting certain conditions, will disconnect the home network and then subsequently connect to a different network. Keep in mind, the primary application of this software will be on Windows and Linux systems.

Any tips would be a massive help, thanks!

Upvotes: 0

Views: 227

Answers (1)

AlessioDP
AlessioDP

Reputation: 88

You should use Runtime exec to use os commands via Java.

This is OS depend so you need to check which command to use, for example (assuming it is a wireless network):

// Windows
Runtime.getRuntime().exec("netsh wlan disconnect");
// Linux
Runtime.getRuntime().exec("ifconfig wlan0 down");

Technet docs for netsh wlan connect.

Upvotes: 2

Related Questions