-1

I have a Java program to run on an Ubuntu box. This program should ask the user to enter the login and password of the wifi network with which it wants to connect and then the Java program must use the login and pass to connect automatically.

I found iwconfigm but it doesn't work

I launched the command:

iwconfig wlan0 essid login key pass
Error for wireless request "Set Encode" (8B2A)
       invalide argument "pass"

So, how do I connect to the wireless network via the command line?

1

The problem with giving this answer is that there is not a single answer, but very many, depending on the authorization scheme used.

Since most home networks use WPA/WPA2 with PSK, I will tell you how to do it in this case. A proper treatment of all possible subcases is too long for this forum.

   wpa_passphrase your_network_name your_password > wpa.conf
   ifconfig wlan0 down
   ifconfig wlan0 up
   iwconfig wlan0 essid your_network_name
   wpa_supplicant -B -Wnl80211 -i wlan0 -c wpa.conf
   dhclient wlan0

These commands have to be executed as root.

  • +1. what does iwconfig wlan0 essid your_network_name do? Is it necessary? See unix.stackexchange.com/questions/198482/… – Tim Apr 25 '15 at 2:14
  • @Tim Yes it is. It instructs your pc which NIC to use (wlan0, in the case above, you might have more than one) and which network to join: essid is the keyword for the command, then you must provide the name of the wifi network you choose to join, there might be several available. – MariusMatutiae Apr 25 '15 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.