def _connect_to_wpa_ctrl_iface(self): """ Connect to the wpa ctrl interface. """ ctrl_iface = '/var/run/wpa_supplicant' socket_loc = os.path.join(ctrl_iface, self.iface) if os.path.exists(socket_loc): try: return wpactrl.WPACtrl(socket_loc) except wpactrl.error, e: print "Couldn't open ctrl_interface: %s" % e return None
def _connect_to_wpa_ctrl_iface(self): """Connect to the wpa ctrl interface.""" ctrl_iface = '/var/run/wpa_supplicant' socket_loc = os.path.join(ctrl_iface, self.iface) if os.path.exists(socket_loc): try: return wpactrl.WPACtrl(socket_loc) except wpactrl.error as e: print(("Couldn't open ctrl_interface: %s" % e)) return None else: print(f"Couldn't find a wpa_supplicant ctrl_interface for iface " f"{self.iface}") return None
def wpa_ctrl(self): wpa = wpactrl.WPACtrl('/var/run/hostapd/wlan0') wpa.attach() while True: evt = wpa.recv() if not evt: print 'breaking no events' break args = evt.split() event_name = args[0][3:] { 'AP-STA-CONNECTED': self.client_connect, 'AP-STA-DISCONNECTED': self.client_disconnect }[event_name](*args[1:]) wpa.detach()
def wpa_ctrl(self): wpa = wpactrl.WPACtrl('/var/run/hostapd-phy0/wlan0') wpa.attach() config = wpa.get_config() print('Bssid:{}'.format(config.bssid)) print('SSID:{}'.format(config.ssid)) while True: evt = wpa.recv(1024) if not evt: print 'Breaking no events' break print evt args = evt.split() event_name = args[0][3:] { 'AP-STA-CONNECTED': self.client_connect, 'AP-STA-DISCONNECTED': self.client_disconnect }[event_name](*args[1:])
if os.path.isdir(run): try: sockets = [os.path.join(run, i) for i in os.listdir(run)] except OSError, error: print 'Error:', error sys.exit(1) if len(sockets) < 1: print 'No wpa_ctrl sockets found in %s, aborting.' % run sys.exit(1) for s in sockets: try: print '>>> # Open a ctrl_iface connection' print '>>> wpa = wpactrl.WPACtrl("%s")' % s wpa = wpactrl.WPACtrl(s) print '>>> # Location of ctrl_iface socket' print '>>> wpa.ctrl_iface_path' print wpa.ctrl_iface_path print '>>> # Request a few commands' print '>>> wpa.request("PING")' print wpa.request('PING') print '>>> wpa.request("STATUS")' print wpa.request('STATUS') print '>>> wpa.request("LIST_NETWORKS")' print wpa.request('LIST_NETWORKS')
def wpas_connect(): ifaces = [] if os.path.isdir(wpas_ctrl): try: ifaces = [os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)] except OSError, error: print "Could not find wpa_supplicant: ", error return None if len(ifaces) < 1: print "No wpa_supplicant control interface found" return None for ctrl in ifaces: try: wpas = wpactrl.WPACtrl(ctrl) return wpas except wpactrl.error, error: print "Error: ", error pass return None def wpas_tag_read(message): wpas = wpas_connect() if (wpas == None): return print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex")) def wpas_get_handover_req():
def start_wpa(self, path): wpa = wpactrl.WPACtrl(path) return wpa
import wpactrl import sys import os import re import time import requests from bs4 import BeautifulSoup ctrl_interface='/var/run/wpa_supplicant/wlan1' wpactr=wpactrl.WPACtrl(ctrl_interface) networks=wpactr.scanresults() open=[] open_ssid=[] open_bssid=[] wpa2=[] wpa2_ssid=[] wpa2_bssid=[] wpa=[] wpa_ssid=[] wpa_bssid=[] portal_networks=[] wps=[] wps_ssid=[] wps_bssid=[] def main():
def __init__(self, connection=Socketaddress): threading.Thread.__init__(self) self.daemon = True self.wpa_event = wpactrl.WPACtrl(connection) self.wpa_event.attach()
################ if __name__ == "__main__": # Set up GPIO: GPIO.setmode( GPIO.BOARD) # use board pin numbers rather than cpu pin numbers GPIO.setup(Buttonpin, GPIO.IN) # Button (pulled down) GPIO.setup(LEDpin, GPIO.OUT) # indicator LED GPIO.output(LEDpin, GPIO.LOW) # Set up the socket connection for controlling hostapd: wpa = wpactrl.WPACtrl(Socketaddress) # Initialise our threads: blinker = blinkThread() monitor = messageMonitor() monitor.start() # Monitor will run continuously for length of program messageblink(2, 12) # Show that we're ready to go! # Main loop: while True: if GPIO.input(Buttonpin): time.sleep(2) if GPIO.input(Buttonpin) and blinker.isAlive(