Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

lj-wpaclient

Native Lua implementation of client for wpa_supplicant control protocol, (c.f., https://w1.fi/cgit/hostap/tree/src/common/wpa_ctrl.c).

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
end
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()

About

wpa_supplicant client library for LuaJIT

Topics

Resources

Releases

No releases published

Packages

No packages published