-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteven_uds_wpa.py
More file actions
61 lines (52 loc) · 1.56 KB
/
steven_uds_wpa.py
File metadata and controls
61 lines (52 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This is a unix domain socket example for wpa_supplicant
#!/usr/bin/env python
import socket
import sys
import os
#SERVER_PATH = "/tmp/python_unix_socket_server"
SERVER_PATH = "/var/run/wpa_supplicant/wlan0"
CLIENT_PATH = "/tmp/qooq"
try:
os.unlink(CLIENT_PATH)
except IOError:
if os.path.exists(CLIENT_PATH):
raise
def recvall(sock, n):
data = b''
while len(data) < n:
print("Q")
packet = sock.recv(n - len(data))
if not packet:
return None
data += packet
return data
def run_unix_domain_socket_client():
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
sock.bind(CLIENT_PATH)
# Connect the socket to the path where the server is listening
server_address = SERVER_PATH
print("connecting to {:s}".format(server_address))
try:
sock.connect(server_address)
except socket.error as msg:
print(msg)
sys.exit(1)
try:
message = "ATTACH"
print("Sending [{!r}]".format(message))
sock.sendall(bytes(message, 'utf-8'))
data = sock.recv(1024)
#print("Received [{:s}]".format(data))
print("Received [{!r}]".format(data))
#print("Received [%s]" % data)
while 1:
msg = input('Enter command\n')
sock.sendall(bytes(msg, 'utf-8'))
#data = sock.recv(1024)
data = recvall(sock, 4)
print("Received [{!r}]".format(data))
finally:
print ("Closing client")
sock.close()
if __name__ == '__main__':
run_unix_domain_socket_client()