awkman / pywifi Goto Github PK
View Code? Open in Web Editor NEWA cross-platform module for manipulating WiFi devices.
License: MIT License
A cross-platform module for manipulating WiFi devices.
License: MIT License
This code doesn't work without a timeout between the scan and the scan_results method on Windows:
import pywifi, logging
wifi = pywifi.PyWiFi()
wifi._logger.setLevel(logging.DEBUG)
interfaces = wifi.interfaces()
for interface in interfaces:
interface.scan()
print (interface.scan_results())
Result:
>>> import pywifi, logging
>>> wifi = pywifi.PyWiFi()
>>> wifi._logger.setLevel(logging.DEBUG)
>>> interfaces = wifi.interfaces()
pywifi 2019-11-06 02:24:36,376 INFO Get interface: Qualcomm Atheros QCA9377 Wireless Network Adapter
>>>
>>> for interface in interfaces:
... interface.scan()
... print (interface.scan_results())
...
pywifi 2019-11-06 02:24:36,569 INFO iface 'Qualcomm Atheros QCA9377 Wireless Network Adapter' scans
pywifi 2019-11-06 02:24:36,571 DEBUG Scan found 15 networks.
[]
>>> # after a second
...
>>> interfaces[0].scan_results()
pywifi 2019-11-06 02:25:02,709 DEBUG Scan found 13 networks.
pywifi 2019-11-06 02:25:02,712 INFO Find bss:
...TRUNCATED...
pywifi 2019-11-06 02:25:02,752 INFO Find bss:
pywifi 2019-11-06 02:25:02,753 INFO bssid: bc:34:00:11:7d:42:
pywifi 2019-11-06 02:25:02,753 INFO ssid: APW40-01
pywifi 2019-11-06 02:25:02,753 INFO freq: 2462000
pywifi 2019-11-06 02:25:02,754 INFO auth: [0]
pywifi 2019-11-06 02:25:02,754 INFO akm: [4]
pywifi 2019-11-06 02:25:02,755 INFO signal: -83
[<pywifi.profile.Profile object at 0x0338A058>, <pywifi.profile.Profile object at 0x0336B940>, <pywifi.profile.Profile object at 0x0336BCE8>, <pywifi.profile.Profile object at 0x0336BEE0>, <pywifi.profile.Profile object at 0x0336BCA0>, <pywifi.profile.Profile object at 0x0336BB80>, <pywifi.profile.Profile object at 0x033BBD60>, <pywifi.profile.Profile object at 0x033BBD78>, <pywifi.profile.Profile object at 0x033BBF40>, <pywifi.profile.Profile object at 0x033BBF88>, <pywifi.profile.Profile object at 0x033BBB98>, <pywifi.profile.Profile object at 0x033BBD18>, <pywifi.profile.Profile object at 0x03562328>]
Would it be possible for scan to not finish before scan_results has the data available?
Another issue I noticed was that if I simply loop until scan_results doesn't return an empty list, the output I get is a list of just one or a subset of the Wi-Fi networks from the scan. If I call scan_results a second later (without calling scan again) it'll have the complete list of networks:
Code:
import pywifi, itertools, sys, time
from datetime import datetime
wifi = pywifi.PyWiFi()
interfaces = wifi.interfaces()
networks = []
timeout = 5
start_time = time.time()
for interface in interfaces:
interface.scan()
while time.time() < start_time + timeout and networks == []:
for interface in interfaces:
if interface.scan_results() == []:
print ("{}: nothing yet".format(datetime.now().isoformat(sep=' ', timespec='milliseconds')))
continue
else:
print ([x.ssid for x in interface.scan_results()])
for network in interface.scan_results():
networks += [(network.bssid, network.signal, network.ssid, network.key, network.id, network.cipher, network.freq, network.auth, network.akm)]
print ("Waiting half a second")
time.sleep(0.5)
print ([x.ssid for x in interface.scan_results()])
print ("Waiting 1 second")
time.sleep(1)
print ([x.ssid for x in interface.scan_results()])
break
Result:
C:\Users\1oh1\Desktop>python3 scan-wifi.py
2019-11-06 03:07:22.903: nothing yet
2019-11-06 03:07:22.904: nothing yet
2019-11-06 03:07:22.904: nothing yet
2019-11-06 03:07:22.905: nothing yet
2019-11-06 03:07:22.905: nothing yet
2019-11-06 03:07:22.906: nothing yet
2019-11-06 03:07:22.906: nothing yet
2019-11-06 03:07:22.906: nothing yet
2019-11-06 03:07:22.907: nothing yet
2019-11-06 03:07:22.907: nothing yet
2019-11-06 03:07:22.908: nothing yet
2019-11-06 03:07:22.908: nothing yet
2019-11-06 03:07:22.908: nothing yet
2019-11-06 03:07:22.909: nothing yet
2019-11-06 03:07:22.909: nothing yet
2019-11-06 03:07:22.910: nothing yet
2019-11-06 03:07:22.910: nothing yet
2019-11-06 03:07:22.910: nothing yet
2019-11-06 03:07:22.911: nothing yet
['Tails_5G', 'Tails_5G']
Waiting half a second
['Tails_5G', 'D-Link_DIR-615', 'Subhashchandra', 'Subhashchandra', 'APW40-01', 'Xiaomi_779F', 'Ridhi', 'D-Link_DIR-615', 'Tails_5G']
Waiting 1 second
['Tails_5G', 'Tails', 'D-Link_DIR-615', 'Tails_5G', 'Xiaomi_779F', 'Chitra N', 'Tails', 'Falcons Indane', 'Subhashchandra', 'Subhashchandra', 'APW40-01', 'Ridhi', 'D-Link_DIR-615']
It'd be nice if scan_results either returned an empty list or the complete list of networks instead of returning whatever it has at that point of time.
My wifi is broken in an hour.I'm trying to brutely attack to get the password for another wifi.Why I met ERROR Open handle failed after trying a few times later?It has times limit?Or about wifi setting or computer setting?
Perhaps I'm missing something, but the following doesn't work:
>>> import pywifi
>>> iface = pywifi.PyWiFi().interfaces()[0]
>>> iface.scan()
>>> iface.scan_results()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/site-packages/pywifi/iface.py", line 39, in scan_results
return wifiutils.scan_results(self.__raw_obj)
File "/usr/lib/python3.5/site-packages/pywifi/linux/wifiutils.py", line 48, in scan_results
security += tmp_rsn['KeyMgmt']
TypeError: unsupported operand type(s) for +=: 'bool' and 'dbus.Array'
@awkman any idea?
when using iface.scan()
to scan for available networks, the cipher
field in the returned network profiles is always 0, corresponding with const.CIPHER_TYPE_NONE
. this is incorrect, as in my case all available networks actually used cipher type CCMP.
>>> import pywifi
>>> iface = pywifi.PyWiFi().interfaces()[0]
>>> iface.scan()
>>> time.sleep(10)
>>> profiles = iface.scan_results()
>>> [profile.cipher for profile in profiles]
[0, 0, 0, 0, 0, 0, 0]
this means that when adding a key to a profile prior to connecting to it, i also needed to amend the cipher field. e.g. if i wanted to connect to profiles[0]
above, i would have to:
>>> from pywifi import const
>>> profiles[0].cipher = const.CIPHER_TYPE_CCMP
>>> profiles[0].key = "networkpasswordhere"
>>> profile = iface.add_network_profile(profiles[0])
>>> iface.connect(profile)
without setting the cipher type, the profile would not add to the interface. (i believe this may be the cause of issue #45.)
the issue here is that the scan should be able to return the cipher type of each profile; the user shouldn't have to manually determine the cipher type through other means and enter it into the profile. for instance in windows 10, using the netsh
command to scan for available networks returns the cipher type under the attribute 'Encryption'.
>netsh wlan show networks interface="Wi-Fi"
Interface name : Wi-Fi
There are 5 networks currently available
SSID 1 : ExampleSSID
Network type : Infrastructure
Authentication : WPA2-Personal
Encryption : CCMP
...
issue found in Windows 10 and Linux (Ubuntu 19.10), and occurs regardless of whether interface is connected to an AP or in disconnected status when using iface.scan()
.
$ lsb_release -d
Description: Ubuntu 18.04.2 LTS
$ python3 example.py # this is the code from README.md
Traceback (most recent call last):
File "example.py", line 7, in <module>
iface = wifi.interfaces()[0]
File "/home/cor/.local/lib/python3.6/site-packages/pywifi/wifi.py", line 42, in interfaces
for interface in wifi_ctrl.interfaces():
File "/home/cor/.local/lib/python3.6/site-packages/pywifi/_wifiutil_linux.py", line 281, in interfaces
for f in sorted(os.listdir(CTRL_IFACE_DIR)):
PermissionError: [Errno 13] Permission denied: '/var/run/wpa_supplicant'
$ sudo chmod 755 /var/run/wpa_supplicant
$ python3 example.py
Traceback (most recent call last):
File "example.py", line 7, in <module>
iface = wifi.interfaces()[0]
File "/home/cor/.local/lib/python3.6/site-packages/pywifi/wifi.py", line 42, in interfaces
for interface in wifi_ctrl.interfaces():
File "/home/cor/.local/lib/python3.6/site-packages/pywifi/_wifiutil_linux.py", line 288, in interfaces
self._connect_to_wpa_s(f)
File "/home/cor/.local/lib/python3.6/site-packages/pywifi/_wifiutil_linux.py", line 304, in _connect_to_wpa_s
sock.connect(ctrl_iface)
PermissionError: [Errno 13] Permission denied
$
I am on Windows10 with python 2.7.12
`>>> wifi.interfaces()[0].scan()
wifi.interfaces()[0].scan_results
<bound method Interface.scan_results of <pywifi.iface.Interface instance at 0x0313CAF8>>
wifi.interfaces()[0].scan_results()
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\pywifi\iface.py", line 39, in scan_results
return wifiutils.scan_results(self.__raw_obj)
File "C:\Python27\lib\site-packages\pywifi\win\wifiutils.py", line 30, in scan_results
network['ssid'] += "%c" % bsses[i].dot11Ssid.ucSSID[j]
IndexError: string index out of range
wifi.interfaces()[0].status
<bound method Interface.status of <pywifi.iface.Interface instance at 0x0313CAF8>>
wifi.interfaces()[0].status()
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\pywifi\iface.py", line 74, in status
return wifiutils.status(self.__raw_obj)
File "C:\Python27\lib\site-packages\pywifi\win\wifiutils.py", line 186, in status
data = wifiapi.PDWORD()
AttributeError: 'module' object has no attribute 'PDWORD'`
is the error.
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import pywifi
Traceback (most recent call last):
File "", line 1, in
File "pywifi/init.py", line 15, in
from .wifi import PyWiFi
File "pywifi/wifi.py", line 15, in
from .iface import Interface
File "pywifi/iface.py", line 15, in
raise NotImplementedError
NotImplementedError
pip showed that pywifi is installed correctly
freshly installed Python 3.5.4 on Windows 10 (version 1803 OS Build 17134.407) using official install executable.
using latest master branch (as of writing) of pywifi. installed with pip. install succeeded no errors:
running this code from example in README:
import pywifi
import time
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.disconnect()
time.sleep(1)
assert iface.status() in\
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
results in:
Traceback (most recent call last):
File "wifi.py", line 10, in <module>
assert iface.status() in\
File "C:\Users\<username>\AppData\Local\Programs\Python\Python35\lib\site-packages\pywifi\iface.py", line 113, in status
return self._wifi_ctrl.status(self._raw_obj)
File "C:\Users\<username>\AppData\Local\Programs\Python\Python35\lib\site-packages\pywifi\_wifiutil_win.py", line 473, in status
return status_dict[data.contents.value]
ValueError: NULL pointer access
Same problem if I call iface.status()
. The WLAN AutoConfig service is running.
On Windows 10 under Python 2.7.10 and 2.7.13 (the two versions I tested) package "comtypes" is not installed by default causing an exception during import. After installing it with pip works perfectly :)
profile=pywifi.Profile()
profile.ssid="apssid"
iface.remove_all_network_profiles()
tmp_profile=iface.add_network_profile(pf)
iface.connect(tmp_profile)
I got this and when iface.connect(tmp_profile)
gets executed.
AttributeError: 'NoneType' object has no attribute 'ssid'
it seems the add_network_profile method is returning a NoneType object instead of a profile object, is there anything wrong with my code? Thanks
It seems that the requirments might be messing up pip on windows.
C:\Users\chibi>pip install pywifi
Collecting pywifi
Could not find a version that satisfies the requirement pywifi (from versions: 1.0.2.linux-x86_64)
No matching distribution found for pywifi
On windows it shouldn't care about that.
Yet if I download the zip of the repo and run pip install . in the directory with setup.py it installs just fine. I think it might be a misconfiguration on the PyPi end of pip.
The iface
class appears to have a remove_network_profile()
function that, I assume, is the opposite of add_network_profile()
and removes a single profile. It seems to have two problems:
it takes keyword arguments that are unspecified so eg. remove_network_profile(profile)
fails, because it only takes one positional argument (which is self
), but I have no idea what the argument name is (name=
? profile=
?)
it is connected to a function in the underlying class that doesn't exist in any implementation, so calling it with the correct signature would fail anyway
I don't know enough about the underlying implementations to craft a fix, but given a little info I might be able to create a PR.
When i use pywifi, i find iface.status() shows '4' while my PC's wifi actually is disconnected. I don't know how to solve it. My system is Ubuntu 18.04 LTS and python is 3.7
In the doc.md, the two Authentication Algorithms option is
const.AUTH_OPEN
const.AUTH_SHARED
but int the const.py,the real option is
AUTH_ALG_OPEN = 0
AUTH_ALG_SHARED = 1
please fix it
iface.connect(profile) always return const.IFACE_DISCONNECTED. I use Python3, win10. It cannot connect to my AP even if the key is write.
`
from pywifi import *
import time
def main():
wifi = PyWiFi()
iface = wifi.interfaces()[0]
iface.scan()
time.sleep(1)
scanres = iface.scan_results()
profile = Profile()
for s in scanres:
if s.ssid == 'meilan':
profile.ssid = s.ssid
profile.auth = s.auth
profile.akm.append(s.akm[0])
profile.cipher = s.cipher
break
key = 'abcdefgg'
profile.key = key
profile = iface.add_network_profile(profile)
iface.remove_all_network_profiles()
iface.connect(profile)
time.sleep(30)
print(iface.status())
main()
`
how to support mac os system?
Is there some advice ?
All is in the title of the issue :).
Line 21 in c6ec3ea
This code will add a handler to other loggers.
After pip3.5 install pywifi
>>> import pywifi
>>> pywifi.PyWiFi()
AttributeError: module 'pywifi' has no attribute 'PyWiFi'
Windows 7
Python 2.7.9 32-bit
PyWiFi 1.1.10
When trying to connect to a network, and the SSID or key contains a "<" character, pywifi is not able to create the network profile (looking at Control Panel - Network and Internet - Manage Wireless Networks).
When using < in the Profile.ssid or Profile.key, and calling interface.add_network_profile(), there is no error, but there is also no network profile created. When using <, a network profile is created, but a connection with that profile fails.
I only have a problem with the < character. The >, & or " characters don't show this issue, I can just use them in the SSID or key.
import pywifi
pw = pywifi.PyWiFi()
i = pw.interfaces()[0]
p = pywifi.Profile()
p.ssid = "My<SSID"
i.add_network_profile(p)
# no network profile is created
p.ssid = "My<SSID"
i.add_network_profile(p)
# A network profile "My<SSID" is created, but a connection with that profile fails
Does the interface.scan_result[].signal mean rssi?or dbm
Inherit WifiUtil class from _wifiutil_win and add the following code in your subclass.
def remove_network_profile(self, obj, name):
"""Remove the specified AP settings."""
profile_name_list = super().network_profile_name_list(obj)
for profile_name in profile_name_list:
if name == profile_name:
super()._logger.debug("delete profile: %s", profile_name)
str_buf = create_unicode_buffer(profile_name)
ret = super()._wlan_delete_profile(super()._handle, obj['guid'], str_buf)
super()._logger.debug("delete result %d", ret)
else:
pass
And then,use the method remove_network_profile(iface._raw_obj,profile.ssid) to remove the profile.
The iface is a interface object.
Just opening this to say what i am working on for a PR.
And for comments on it.
it will allow for implementing more of the following.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms707348(v=vs.85).aspx
I want to connect an AP without serurity setting in my win10.
This my code
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
profile = pywifi.Profile()
profile.ssid = 'my-ssid'
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_NONE)
iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
However, it doesn't work and the icon of wlan is disconnected.
I use DEBUD mode and then, it shows iface.add_network_profile(profile) return 1206 status, which show profile has some errors.
I change _wifiutil_win.py L338 to L382 into the following code.
if params.akm[-1] == AKM_TYPE_NONE:
profile_data['auth'] = auth_value_to_str_dict[params.auth].lower()
profile_data['encrypt'] = cipher_value_to_str_dict[params.cipher].lower()
profile_data['mode'] = 'auto'
else:
profile_data['auth'] = akm_value_to_str_dict[params.akm[-1]]
profile_data['encrypt'] = cipher_value_to_str_dict[params.cipher]
profile_data['mode'] = 'manual'
profile_data['key'] = params.key
profile_data['protected'] = 'false'
profile_data['profile_name'] = params.ssid
xml = """<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{profile_name}</name>
<SSIDConfig>
<SSID>
<name>{ssid}</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>{mode}</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>{auth}</authentication>
<encryption>{encrypt}</encryption>
<useOneX>false</useOneX>
</authEncryption>
"""
if params.akm[-1] != AKM_TYPE_NONE:
xml += """<sharedKey>
<keyType>passPhrase</keyType>
<protected>{protected}</protected>
<keyMaterial>{key}</keyMaterial>
</sharedKey>
</security>
</MSM>
"""
else:
xml += """</security>
</MSM>
"""
Occurs when trying to import native_wifi from wifiutils. This is done by using the example provided.
Traceback (most recent call last):
File "C:/Users/goose/PycharmProjects/wifiSwap/main.py", line 1, in <module>
import pywifi
File "C:\Python33\lib\site-packages\pywifi\__init__.py", line 3, in <module>
from .pywifi import *
File "C:\Python33\lib\site-packages\pywifi\pywifi.py", line 5, in <module>
from .iface import Interface
File "C:\Python33\lib\site-packages\pywifi\iface.py", line 7, in <module>
from .win import wifiutils
File "C:\Python33\lib\site-packages\pywifi\win\wifiutils.py", line 6, in <module>
from . import native_wifi as wifiapi
ImportError: cannot import name native_wifi
Not sure if there is an issue with the package or my current setup (using latest version of pycharm). Doesn't seem to have a circular import.
error while trying to import on Fedora 29
Traceback (most recent call last): File "/home/utytlanyjoe/PycharmProjects/testy/wifi/main.py", line 14, in <module> print(w.get_avaliable_interfaces()) File "/home/utytlanyjoe/PycharmProjects/testy/wifi/main.py", line 8, in get_avaliable_interfaces return self.wifi.interfaces() File "/home/utytlanyjoe/PycharmProjects/testy/venv/lib64/python3.7/site-packages/pywifi/wifi.py", line 42, in interfaces for interface in wifi_ctrl.interfaces(): File "/home/utytlanyjoe/PycharmProjects/testy/venv/lib64/python3.7/site-packages/pywifi/_wifiutil_linux.py", line 248, in interfaces for f in os.listdir(CTRL_IFACE_DIR): FileNotFoundError: [Errno 2] No such file or directory: '/var/run/wpa_supplicant'
Should be changed to result of
whereis wpa_supplicant
:
wpa_supplicant: /usr/sbin/wpa_supplicant /etc/wpa_supplicant /usr/share/man/man8/wpa_supplicant.8.gz
I want to use remove_network_profile() API to remove one specified AP settings, but I could not find the example or its code.
Could you help me?
Termux python test pywifi
_wifiutil_android.py
_wifiutil_ios.py
SSID cannot be displayed with Chinese characters
This would be helpful because you could fill in almost all the info in the Profile for a network. (On windows at least.)
(I realize I am making a lot of Issues I just really like using this.)
When a network has many APs, I want to connect to the one I specify for the bssid.
Am testing the module right now but i can't connect to my network, When i check iface.status is says
dbus.String(u'completed', variant_level=1)
I use pywifi can work,but reboot can't auto connection, how to set?
import wifi
def Search():
wifilist = []
cells = wifi.Cell.all('wlan0')
for cell in cells:
wifilist.append(cell)
return wifilist
def FindFromSearchList(ssid):
wifilist = Search()
for cell in wifilist:
if cell.ssid == ssid:
return cell
return False
def FindFromSavedList(ssid):
cell = wifi.Scheme.find('wlan0', ssid)
if cell:
return cell
return False
def Connect(ssid, password=None):
cell = FindFromSearchList(ssid)
if cell:
savedcell = FindFromSavedList(cell.ssid)
if savedcell:
savedcell.activate()
return cell
else:
if cell.encrypted:
if password:
scheme = Add(cell, password)
try:
scheme.activate()
# Wrong Password
except wifi.exceptions.ConnectionError:
Delete(ssid)
return False
return cell
else:
return False
else:
scheme = Add(cell)
try:
scheme.activate()
except wifi.exceptions.ConnectionError:
Delete(ssid)
return False
return cell
return False
def Add(cell, password=None):
if not cell:
return False
scheme = wifi.Scheme.for_cell('wlan0', cell.ssid, cell, password)
scheme.save()
return scheme
def Delete(ssid):
if not ssid:
return False
cell = FindFromSavedList(ssid)
if cell:
cell.delete()
return True
return False
if name == 'main':
# Search WiFi and return WiFi list
print Search()
print Connect('OpenWiFi')
print Connect('ClosedWiFi', 'password')
print Delete('DeleteWiFi')
I have two wifi device.
One in my computer is "Qualcomm Atheros AR9285 Wireless Netword Adapter"
Another is "802.11n USB Wireless LAN Card"
I can use either of them to connect wifi for Internet.
BUT, I use
ifacelist=pywifi.PyWiFi().interfaces()
in this list, I can only get one iface. Sometimes it is the first device, sometimes it is the second device. This confussed me, How could I get both of them?
freshly installed Python 3.5.4 on Windows 10 (version 1803 OS Build 17134.407) using official install executable.
using latest master branch (as of writing) of pywifi. installed with pip. install succeeded no errors:
running this code:
import pywifi
wifi = pywifi.PyWiFi()
wifi.interfaces()
results in:
pywifi 2018-11-16 17:12:02,183 ERROR Open handle failed!
pywifi 2018-11-16 17:12:02,183 ERROR Enum interface failed!
>>> import pywifi
>>> iface = pywifi.PyWiFi().interfaces()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pywifi/pywifi.py", line 23, in interfaces
for interface in wifiutils.interfaces():
NameError: name 'wifiutils' is not defined
Hi,
great module, thanks for making it :)
Is there any why to detect the name of currently connected ssid?
Thanks
I can use this module to establish a wifi connection in Windows, my code is as follows:
wifi=PyWiFi()
ifaces=wifi.interfaces()[0]
print(ifaces.name())
print(const.IFACE_CONNECTED)
print(const.IFACE_INACTIVE)
profile = pywifi.Profile()
profile.ssid = ""
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = "**"
tmp_profile = ifaces.add_network_profile(profile)
ifaces.connect(tmp_profile)
time.sleep(5)
if ifaces.status() == const.IFACE_CONNECTED:
print("OK")
else:
print("ERROR")`
Now I wann make a wifi connection on Raspberry pi,using this code not succeed.
The "Prerequisites" : "On Linux, you will need to run wpa_supplicant to manipulate the wifi devices, and then pywifi can communicate with wpa_supplicant through socket." I think I should start here, but I don't know how to do it in particular. could you give me some advice? Thanks
Why 'iface.status()' return always a null value ? I try simply establish a connection with created profile
My OS : Windows 10
My python : 3.6.2
What is there a solution for this bug ?
My code :
from pywifi import *
import time
wifi = PyWiFi()
iface = wifi.interfaces()[0]
iface.scan()
scan_results = []
iface.disconnect()
if len(scan_results) == 0:
print("Wait 3 secondes")
time.sleep(3)
scan_results = iface.scan_results()
if len(scan_results) != 0:
print(scan_results)
for r_wifi in scan_results:
#print(r_wifi.ssid)
if r_wifi.ssid == 'toto':
print("> toto : " + str(r_wifi.ssid))
profile = Profile()
profile.ssid = r_wifi.ssid
profile.auth = r_wifi.auth
profile.akm.append(r_wifi.akm[0])
profile.cipher = r_wifi.cipher
key = 'mpkihy947'
profile.key = key
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
time.sleep(10)
print("STATUT")
print(iface.status())
i have a embedded board named Raspberry PI,this board is based on arm linux instead of x64 linux.
Can i use "pywifi" in my board?
If i can,how to install this module?
Thank you.
>>> #tested on windows 10
>>> import pywifi
>>> wifi = pywifi.PyWiFi()
>>> iface = wifi.interfaces()[0]
>>> iface
<pywifi.iface.Interface object at 0x02F4D670>
>>> iface.scan()
>>> iface.scan_results()[0].bssid
'xx:xx:xx:xx:12:e3:'
Bssids should not end with an ":"
➜ ~ $ pip3 install pywifi
Collecting pywifi
Downloading https://files.pythonhosted.org/packages/89/55/170a52685eeefeab36bfaf26bdca629263a0a28efffc3b556b2cc86ab966/pywifi-1.1.12-py3-none-any.whl
Installing collected packages: pywifi
Successfully installed pywifi-1.1.12
You are using pip version 19.0.3, however version 19.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
➜ ~ $ python3
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywifi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pywifi/__init__.py", line 15, in <module>
from .wifi import PyWiFi
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pywifi/wifi.py", line 15, in <module>
from .iface import Interface
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pywifi/iface.py", line 15, in <module>
raise NotImplementedError
NotImplementedError
>>> exit()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.