Skip to content

Instantly share code, notes, and snippets.

@artizirk
Created April 3, 2016 21:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artizirk/cd3980c8ff870eb0bfce68bc26a2676b to your computer and use it in GitHub Desktop.
Save artizirk/cd3980c8ff870eb0bfce68bc26a2676b to your computer and use it in GitHub Desktop.
A small example of connecting to wpa_supplicant daemon control socket that is also used by wpa_cli with python
import os
import select
import socket
interface = "wlan1"
wpa_send_path = "/run/wpa_supplicant/"+interface
wpa_recv_path = "/tmp/wpa_ctrl_{pid}-{count}".format(pid=os.getpid(), count=1)
soc = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
soc.bind(wpa_recv_path)
soc.connect(wpa_send_path)
print("> PING")
soc.send(b"PING")
print("<", soc.recv(4096).decode().strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment