This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathwlan.py
185 lines (151 loc) · 3.91 KB
/
wlan.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from network import WLAN
import os
import time
print (type(WLAN))
'''
def wait_for_connection(wifi, timeout=10):
while not wifi.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wifi.isconnected():
print('Connected')
else:
print('Connection failed!')
wifi = WLAN(WLAN.STA)
print(wifi.mode() == WLAN.STA)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.AP)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 1)
print(wifi.auth() == None)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(0, mode=WLAN.AP, ssid='test-wlan', auth=(WLAN.WPA, '123456abc'), channel=7)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 7)
print(wifi.ssid() == 'test-wlan')
print(wifi.auth() == (WLAN.WPA, '123456abc'))
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.STA)
print(wifi.mode() == WLAN.STA)
time.sleep(5) # this ensures a full network scan
scan_r = wifi.scan()
print(len(scan_r) > 0)
for net in scan_r:
if len(net.ssid)<1:
print("Failed ssid check")
if len(net.bssid)!=6:
print("Failed bssid check")
if net.rssi > 0:
print("Failed rss check")
if net.channel < 1 or net.channel > 14:
print("Failed channel check")
if net.sec < 0:
print("Failed channel sec")
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.channel(7)
print(wifi.channel() == 7)
wifi.ssid('t-wlan')
print(wifi.ssid() == 't-wlan')
wifi.auth(None)
print(wifi.auth() == None)
wifi.auth((WLAN.WEP, '11223344556677889900'))
print(wifi.auth() == (WLAN.WEP, '11223344556677889900'))
wifi.antenna(WLAN.INT_ANT)
print(wifi.antenna() == WLAN.INT_ANT)
wifi.antenna(WLAN.EXT_ANT)
print(wifi.antenna() == WLAN.EXT_ANT)
time.sleep(2) # this ensures a full network scan
scan_r = wifi.scan()
print (scan_r)
print(len(scan_r) > 0)
'''
'''
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
print('Network found')
break
wifi.antenna(WLAN.INT_ANT)
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=10000)
wait_for_connection(wifi)
wifi.ifconfig(config='dhcp')
wait_for_connection(wifi)
print('0.0.0.0' not in wifi.ifconfig())
wifi.ifconfig(0, ('192.168.178.109', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
wait_for_connection(wifi)
print(wifi.ifconfig(0) == ('192.168.178.109', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
wait_for_connection(wifi)
print(wifi.isconnected() == True)
wifi.disconnect()
print(wifi.isconnected() == False)
t0 = time.ticks_ms()
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
print(time.ticks_ms() - t0 < 500)
wifi.disconnect()
print(wifi.isconnected() == False)
# test init again
wifi.init(mode = WLAN.AP, ssid='www.wipy.io', auth=None, channel=5, antenna=WLAN.INT_ANT)
print(wifi.mode() == WLAN.AP)
# get the current instance without re-init
wifi = WLAN()
print(wifi.mode() == WLAN.AP)
wifi = WLAN(0)
print(wifi.mode() == WLAN.AP)
# test the MAC address length
print(len(wifi.mac()) == 6)
# next ones MUST raise
try:
wifi.init(mode=12345)
except:
print('Exception')
try:
wifi.init(1, mode=WLAN.AP)
except:
print('Exception')
try:
wifi.init(mode=WLAN.AP, ssid=None)
except:
print('Exception')
try:
wifi = WLAN(mode=WLAN.AP, channel=12)
except:
print('Exception')
try:
wifi.antenna(2)
except:
print('Exception')
try:
wifi.mode(10)
except:
print('Exception')
try:
wifi.ssid('11111sdfasdfasdfasdf564sdf654asdfasdf123451245ssdgfsdf1111111111111111111111111234123412341234asdfasdf')
except:
print('Exception')
try:
wifi.auth((0))
except:
print('Exception')
try:
wifi.auth((0, None))
except:
print('Exception')
try:
wifi.auth((10, 10))
except:
print('Exception')
try:
wifi.channel(0)
except:
print('Exception')
try:
wifi.ifconfig(1, 'dhcp')
except:
print('Exception')
try:
wifi.ifconfig(config=())
except:
print('Exception')
'''