2016-10-05 01:44:27 +02:00
|
|
|
#!/usr/bin/python3
|
2017-03-26 03:16:53 +02:00
|
|
|
import os, os.path
|
|
|
|
import wiphy
|
|
|
|
|
|
|
|
hostapd_map = {ifname: intf for wname, wiphy in wiphy.wiphy_map.items()
|
|
|
|
for ifname, intf in wiphy.items() if intf.use == 'hostapd'}
|
2016-10-05 01:44:27 +02:00
|
|
|
|
|
|
|
class HostapdCLI:
|
2017-03-26 03:16:53 +02:00
|
|
|
def __init__(self, interface):
|
|
|
|
self.ifname = interface.name
|
|
|
|
self.ctrl_interface = interface.ctrl_interface
|
2016-10-05 01:44:27 +02:00
|
|
|
|
2017-03-26 03:16:53 +02:00
|
|
|
socket_path = os.path.dirname(self.ctrl_interface)
|
2016-10-06 20:06:14 +02:00
|
|
|
|
2017-03-26 03:16:53 +02:00
|
|
|
self.cmdline = 'hostapd_cli -p"' + socket_path + '" -i"' + \
|
|
|
|
self.ifname + '"'
|
|
|
|
|
|
|
|
def wps_push_button(self):
|
|
|
|
os.system(self.cmdline + ' wps_pbc')
|
|
|
|
|
|
|
|
def deauthenticate(self, client_address):
|
|
|
|
os.system(self.cmdline + ' deauthenticate ' + client_address)
|
2016-10-06 20:06:14 +02:00
|
|
|
|
2017-03-26 03:16:57 +02:00
|
|
|
def reload(self):
|
|
|
|
# Seemingly all three commands needed for the instance to notice
|
|
|
|
# interface's address change
|
|
|
|
cmds = 'reload\ndisable\nenable\n'
|
|
|
|
proc = os.popen(self.cmdline, mode='w')
|
|
|
|
lines = proc.write(cmds)
|
|
|
|
proc.close()
|
|
|
|
|
|
|
|
def list_sta(self):
|
|
|
|
proc = os.popen(self.cmdline + ' list_sta')
|
|
|
|
lines = proc.read()
|
|
|
|
proc.close()
|
|
|
|
|
|
|
|
return [line for line in lines.split('\n') if line]
|
|
|
|
|
|
|
|
def set_neighbor(self, addr, ssid, nr):
|
|
|
|
os.system(self.cmdline + ' set_neighbor ' + addr + ' ssid=\\""' + ssid +
|
|
|
|
'"\\" nr=' + nr)
|
|
|
|
|
2016-10-06 20:06:14 +02:00
|
|
|
@staticmethod
|
|
|
|
def kill_all():
|
|
|
|
os.system('killall hostapd')
|