Buras
Buras

Reputation: 3099

How to connect to a wireless network programmatically?

I have a java application and two different wireless network connections (wifi) on my desktop. This is a desktop application, not android.

One method of this applicaiton works well with wifi1, second method works well with wifi2.

So far in order to use different methods I have to change wifi settings on my desktop manually.

Is there any way I could change wifi connection setting from the application programmatically ?

Upvotes: 1

Views: 4973

Answers (1)

Mike Knooihuisen
Mike Knooihuisen

Reputation: 204

Java is a High-Level, Platform-Independent programming language. Network settings, and how you control them will depend on your Operating System, and to my knowledge there is no simple way to expose this in Java.

' Luckily, some platform-dependent code mixed with Java can help you achieve the result you're after.

  1. The Java

    See the Runtime.exec() method, which allows you access to the Windows Command Line or the Mac/Linux Terminal.

  2. The Windows (Adjust for other OS'es)

    Now that we have access to the Command Line, we have to run the proper, platform-specific command. See this tutorial for Windows.

Note that it is not a good idea to modify a user's network settings (or anything else external to your application) without their consent.

Upvotes: 5

Related Questions