Skip to content
wpa_supplicant client library for LuaJIT
Lua C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ffi-cdecl
.editorconfig
.gitignore
LICENSES
README.md
consts_h.lua
poll_h.lua
socket.lua
socket_h.lua
wpa_ctrl.lua
wpaclient.lua

README.md

lj-wpaclient

Native Lua implementation of client for wpa_supplicant control protocol.

Dependencies

  • LuaJIT

Usage

High level APIs are defined in wpaclient.lua. A quick example on how it can be used to communicate with wpa_supplicant server:

local WpaClient = require('wpaclient')
local wcli = WpaClient.new('/var/run/wpa_supplicant/wlan0')
for _, entry in pairs(wcli:scanThenGetResults()) do
    print("quality:", entry:getSignalQuality(),
          "bssid:", entry.bssid,
          "ssid:", (entry.ssid or "[hidden]"),
          "flags:", entry.flags)
end
wcli:close()

Lower level APIs are defined in wpa_ctrl.lua and used in wpaclient.lua. It mimics C APIs defined in wpa_ctrl.h from hostap project.

Listen for events

local WpaClient = require('wpaclient')
local wcli = WpaClient.new('/var/run/wpa_supplicant/wlan0')
wcli:attach()
wcli:doScan()
while true do
    ev = wcli:readEvent()
    if ev ~= nil then
        print('got event:', ev.lvl, ev.msg)
    else
        os.execute('sleep 2')
    end
done
wcli:close()

Add and connect to network

local WpaClient = require('wpaclient')
local wcli = WpaClient.new('/var/run/wpa_supplicant/wlan0')

local nw_id, err = wcli:addNetwork()
print('[*] got network id: ', nw_id)
wcli:setNetwork(nw_id, "ssid", "\"random-super-safe-free-wifi\"")
wcli:setNetwork(nw_id, "psk", "\"PASSWORD\"")
-- That's it! Now run your favorite DHCP client to obtain an IP :)
wcli:close()
You can’t perform that action at this time.