wifi.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. # vim: set fileencoding=utf-8
  3. """
  4. wifi - entry module of pywifi libary.
  5. We put the fundamental implementation of wifi functions in each OS
  6. folder (e.g. linux, win, and osx). So, PyWiFi class is just the
  7. entry point to manipulate wifi devices.
  8. """
  9. import platform
  10. import logging
  11. from .iface import Interface
  12. if platform.system().lower() == 'windows':
  13. from . import _wifiutil_win as wifiutil
  14. elif platform.system().lower() == 'linux':
  15. from . import _wifiutil_linux as wifiutil
  16. else:
  17. raise NotImplementedError
  18. class PyWiFi:
  19. """PyWiFi provides operations to manipulate wifi devices."""
  20. _ifaces = []
  21. _logger = None
  22. def __init__(self):
  23. self._logger = logging.getLogger('pywifi')
  24. def interfaces(self):
  25. """Collect the available wlan interfaces."""
  26. self._ifaces = []
  27. wifi_ctrl = wifiutil.WifiUtil()
  28. for interface in wifi_ctrl.interfaces():
  29. iface = Interface(interface)
  30. self._ifaces.append(iface)
  31. self._logger.info("Get interface: %s", iface.name())
  32. if not self._ifaces:
  33. self._logger.error("Can't get wifi interface")
  34. return self._ifaces