diff --git a/pywifi/_wifiutil_win.py b/pywifi/_wifiutil_win.py index e81e64b..71288cd 100755 --- a/pywifi/_wifiutil_win.py +++ b/pywifi/_wifiutil_win.py @@ -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/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