From 7bc53ccc556d997e7e2f9cbd7bf4b021daab8008 Mon Sep 17 00:00:00 2001 From: hktkqj Date: Sat, 29 Sep 2018 14:31:41 +0800 Subject: [PATCH 1/4] UTF-8 encode SSID test --- tests/wifi.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/wifi.py diff --git a/tests/wifi.py b/tests/wifi.py new file mode 100644 index 0000000..13e9b12 --- /dev/null +++ b/tests/wifi.py @@ -0,0 +1,51 @@ +#coding=utf-8 +import pywifi +import time +A = 41 +n = 3.7 +wifi = pywifi.PyWiFi() +iface = wifi.interfaces()[0] +iface.scan() +result=iface.scan_results() +time.sleep(2) + +for i in range(len(result)): + SSID = result[i].ssid + SIGNAL = result[i].signal + RSSI = SIGNAL + length = pow(10, ((abs(RSSI) - A) / (10 * n))) + if SSID != "NWPU-WLAN": + if SSID != "NWPU-CHANGAN": + if SSID != "CMCC-EDU": + if SSID != "CMCC-xbgy": + if SSID != "CMCC-freegame": + s = SSID.encode() + cnt = 0 + res = 0 + lst = [] + name = "" + for char in SSID : + if (33<=ord(char)<=126) : + name = name + char + else : + cnt = cnt + 1 + now = int(str(bin(ord(char)))[2:6],2) + now1 = int(str(bin(ord(char)))[6:10], 2) + res = res + now * 16 + now1 + lst.append(res) + res = 0 + if cnt == 3 : + name = name +bytes(lst).decode('utf-8','ignore') + lst = [] + res = 0 + cnt = 0 + print(str(name) + ' ' + str(SIGNAL) + " %.2f" % length + ' m') + + + + '''length=pow(10,((abs(RSSI) - A) / (10 * n))) + print(SSID+' '+str(SIGNAL)+" %.2f" % length + ' m') + #d - 计算所得距离(单位:m) + #rssi - 接收信号强度 + #A - 发射端和接收端相隔1米时的信号强度 + #n - 环境衰减因子''' From bf527f6d08eb9886c3bbab91fb99a75c7ba2903d Mon Sep 17 00:00:00 2001 From: hktkqj Date: Sat, 29 Sep 2018 16:14:01 +0800 Subject: [PATCH 2/4] Modified _wifiutil_win.py to made SSID displayed in UTF-8 --- pywifi/_wifiutil_win.py | 26 ++++++++++++++++++++++++-- tests/Modify.py | 0 tests/wifi.py | 28 +++++----------------------- 3 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 tests/Modify.py diff --git a/pywifi/_wifiutil_win.py b/pywifi/_wifiutil_win.py index e81e64b..5f42718 100755 --- a/pywifi/_wifiutil_win.py +++ b/pywifi/_wifiutil_win.py @@ -90,7 +90,7 @@ CIPHER_TYPE_WEP: 'WEP', CIPHER_TYPE_TKIP: 'TKIP', CIPHER_TYPE_CCMP: 'AES', - CIPHER_TYPE_UNKNOWN: 'UNKNOWN' + CIPHER_TYPE_UNKNOWN: 'UNKtemp_nowN' } class WLAN_INTERFACE_INFO(Structure): @@ -277,7 +277,29 @@ def scan_results(self, obj): if networks[i].dot11Ssid.ucSSID != b'': ssid += "%c" % networks[i].dot11Ssid.ucSSID[j] - + #This part is used for converting to UTF-8 encoded SSID + temp_cnt = 0 + temp_hex_res = 0 + bytes_list = [] + converted_name = "" + for bin_encode_char in ssid: + if (33 <= ord(bin_encode_char) <= 126): + converted_name = converted_name + bin_encode_char + else: + temp_cnt = temp_cnt + 1 + temp_now = int(str(bin(ord(bin_encode_char)))[2:6], 2) + temp_now1 = int(str(bin(ord(bin_encode_char)))[6:10], 2) + temp_hex_res = temp_hex_res + temp_now * 16 + temp_now1 + bytes_list.append(temp_hex_res) + temp_hex_res = 0 + if temp_cnt == 3: + converted_name = converted_name + bytes(bytes_list).decode('utf-8', 'ignore') + bytes_list = [] + temp_hex_res = 0 + temp_cnt = 0 + ssid = converted_name + #print("Work + " + ssid + " strlen : " + str(len(ssid))) + #End of converting part bss_list = pointer(WLAN_BSS_LIST()) self._wlan_get_network_bss_list(self._handle, byref(obj['guid']), byref(bss_list), networks[i].dot11Ssid, networks[i].bSecurityEnabled) diff --git a/tests/Modify.py b/tests/Modify.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/wifi.py b/tests/wifi.py index 13e9b12..1312a9f 100644 --- a/tests/wifi.py +++ b/tests/wifi.py @@ -14,33 +14,15 @@ SIGNAL = result[i].signal RSSI = SIGNAL length = pow(10, ((abs(RSSI) - A) / (10 * n))) + ''' if SSID != "NWPU-WLAN": if SSID != "NWPU-CHANGAN": if SSID != "CMCC-EDU": if SSID != "CMCC-xbgy": - if SSID != "CMCC-freegame": - s = SSID.encode() - cnt = 0 - res = 0 - lst = [] - name = "" - for char in SSID : - if (33<=ord(char)<=126) : - name = name + char - else : - cnt = cnt + 1 - now = int(str(bin(ord(char)))[2:6],2) - now1 = int(str(bin(ord(char)))[6:10], 2) - res = res + now * 16 + now1 - lst.append(res) - res = 0 - if cnt == 3 : - name = name +bytes(lst).decode('utf-8','ignore') - lst = [] - res = 0 - cnt = 0 - print(str(name) + ' ' + str(SIGNAL) + " %.2f" % length + ' m') - + if SSID != "CMCC-freegame" : + ''' + if SSID != "" : + print(str(SSID) + ' ' + str(SIGNAL) + " %.2f" % length + ' m') '''length=pow(10,((abs(RSSI) - A) / (10 * n))) From 976f2ec3d14918fbd1ca4e861195fe12a25457da Mon Sep 17 00:00:00 2001 From: hktkqj Date: Sat, 29 Sep 2018 16:20:35 +0800 Subject: [PATCH 3/4] Little accident... --- pywifi/_wifiutil_win.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywifi/_wifiutil_win.py b/pywifi/_wifiutil_win.py index 5f42718..71288cd 100755 --- a/pywifi/_wifiutil_win.py +++ b/pywifi/_wifiutil_win.py @@ -90,7 +90,7 @@ CIPHER_TYPE_WEP: 'WEP', CIPHER_TYPE_TKIP: 'TKIP', CIPHER_TYPE_CCMP: 'AES', - CIPHER_TYPE_UNKNOWN: 'UNKtemp_nowN' + CIPHER_TYPE_UNKNOWN: 'UNKNOWN' } class WLAN_INTERFACE_INFO(Structure): From addfd97fed6252fe7c7951a8e64579144b3637b2 Mon Sep 17 00:00:00 2001 From: hktkqj Date: Sat, 29 Sep 2018 16:22:13 +0800 Subject: [PATCH 4/4] Removed bad files --- tests/Modify.py | 0 tests/test_wifi.py | 17 +++++++++++++++++ tests/wifi.py | 33 --------------------------------- 3 files changed, 17 insertions(+), 33 deletions(-) delete mode 100644 tests/Modify.py create mode 100644 tests/test_wifi.py delete mode 100644 tests/wifi.py diff --git a/tests/Modify.py b/tests/Modify.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_wifi.py b/tests/test_wifi.py new file mode 100644 index 0000000..df398c0 --- /dev/null +++ b/tests/test_wifi.py @@ -0,0 +1,17 @@ +#coding=utf-8 +import pywifi +import time +A = 41 +n = 3.7 +wifi = pywifi.PyWiFi() +iface = wifi.interfaces()[0] +iface.scan() +result=iface.scan_results() +time.sleep(2) + +for i in range(len(result)): + SSID = result[i].ssid + SIGNAL = result[i].signal + RSSI = SIGNAL + if SSID != "" : + print(str(SSID) + ' ' + str(SIGNAL) + " %.2f" % length + ' m') \ No newline at end of file diff --git a/tests/wifi.py b/tests/wifi.py deleted file mode 100644 index 1312a9f..0000000 --- a/tests/wifi.py +++ /dev/null @@ -1,33 +0,0 @@ -#coding=utf-8 -import pywifi -import time -A = 41 -n = 3.7 -wifi = pywifi.PyWiFi() -iface = wifi.interfaces()[0] -iface.scan() -result=iface.scan_results() -time.sleep(2) - -for i in range(len(result)): - SSID = result[i].ssid - SIGNAL = result[i].signal - RSSI = SIGNAL - length = pow(10, ((abs(RSSI) - A) / (10 * n))) - ''' - if SSID != "NWPU-WLAN": - if SSID != "NWPU-CHANGAN": - if SSID != "CMCC-EDU": - if SSID != "CMCC-xbgy": - if SSID != "CMCC-freegame" : - ''' - if SSID != "" : - print(str(SSID) + ' ' + str(SIGNAL) + " %.2f" % length + ' m') - - - '''length=pow(10,((abs(RSSI) - A) / (10 * n))) - print(SSID+' '+str(SIGNAL)+" %.2f" % length + ' m') - #d - 计算所得距离(单位:m) - #rssi - 接收信号强度 - #A - 发射端和接收端相隔1米时的信号强度 - #n - 环境衰减因子'''