简体   繁体   中英

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!

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM