WiFi – Auto Connect to Any Open Network via CLI Command Line

wifi

I have a Linux server running on a laptop.

I would like it to auto-connect to any open WiFi network automatically. (Without knowing the SSID beforehand)

It's for a remote server deployment of ZoneMinder @ a cabin on a large property. If the burglars are REALLY smart they could get on the WiFi and hack the ZoneMinder server, but I highly doubt it and my "client" aka my parents have the WiFi set to Open.

Best Answer

To have your computer search and connect to ANY Open Wifi modifiy the following two files:

*This was tested on Ubuntu 14.04 x64 Server

/etc/network/interfaces

##Wireless NIC
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface open_wifi inet dhcp

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

##Open_Wifi
network={
    ssid=""
    key_mgmt=NONE
    id_str="open_wifi"
}

Now bring interface down/up and check status.

sudo ifconfig wlan0 down && sudo ifconfig wlan0 up && sudo wpa_cli -i wlan0 status

Look for

wpa_state=COMPLETED

Testing:

use both ifconfig/ping

IF ifconfig show's no private IP and ping should fail

dhclient wlan0

try again and should show privateIP and ping should succeed.

To manually connect via config for debugging use this:

wpa_supplicant -d -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -D wext

-d = debug/verbose -dd == super verbose

-D = driver

wext = "catch-all driver"

I tested with phone via hotspot which is PERFECT because it tells you when a client connects. I also turned off HotSpot and it reconnected when it turned back on! Only down side is if you are in a populated area, like my testing environment, it connected to "Xfinity-Wifi" which is open and then I had to reboot then it seemed to go with my hotspot due to it being a stronger signal. But once it was on XFinity it would not leave it unless I specified the Open Network SSID inside of the wpa_supplicant.conf OR rebooted.

Related Question