Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically connecting to a wifi network in Linux

Tags:

linux

wifi

There are multiple questions regarding this functionality for Android or iOS, but I am attempting to do this on Linux (OpenWrt 15.05 to be specific). I want to scan for wireless networks, present the list to the user, have them select one and send the username/password to the network.

I wrote a quick C program using iw_scan from the wireless_tools package so I can see the wireless networks, but I am having issues trying to determine how to connect to a wireless network. iwconfig from the same package just appears to modify an already existing connection.

I have spent a few hours surfing the web thinking there has got to be a package that already does this since it is such a common use case. Anyone know of one?

Thanks.

like image 456
Wray Avatar asked Oct 31 '22 19:10

Wray


1 Answers

wpa_supplicant

Take a look at wpa_supplicant package. It includes wpa_supplicant daemon that can be controlled via wpa_cli and wpa_gui utilities or D-Bus API.

Programs like wicd and Network Manager uses wpa_supplicant internally.


NetworkManager

You can also use D-Bus API or command line interface (nmcli) for NetworkManager. It provides a higher level abstraction than wpa_supplicant does.

like image 157
gavv Avatar answered Nov 29 '22 11:11

gavv