Pythonのpywifi使用ドキュメント
4053 ワード
文書ディレクトリ 1.Installation: Example:
2.Docmentation: Constants(定数): Authentication Algorithms(認証アルゴリズム): Key Management Type(鍵管理タイプ) Cipher Type: Network Profile(ネットワークプロファイル): Example:
Interface(インタフェース) Get interface information(インタフェース情報の取得):
Pywifiは、ワイヤレスインタフェースを操作するためのプラットフォーム間Pythonモジュールを提供しています.
利点:使いやすい;WindowsとLinuxのサポート
1.Installation:
Example:
2.Docmentation:
Constants(定数):
pywifiでは、以下のconstatnsが定義されています.
Interface Status(インタフェースのステータス):
Interface.status()は、次のstatus codeのいずれかを返します.
Authentication Algorithms(認証アルゴリズム):
認証アルゴリズムはProfileファイルと一致する必要があります.一般的には、ほとんどのAPsがオープンアルゴリズムを使用しています.
KeyManagement Type(鍵管理タイプ)
鍵管理タイプはProfileに割り当てるべきです.普通のAPsの場合、
企業APs使用AKM_TYPE_WPAとAKM_TYPE_WPA2.
Cipher Type(パスワードタイプ):
akmがAKMじゃなかったらTYPE_NONEは、パスワードタイプをProfileに設定する必要があります.接続するAPの設定を参照してください.
Network Profile(ネットワークプロファイル):
Profileは、私たちが接続するAPの設定です.Profileのフィールド:
Example:
Interface(インタフェース)
Interfaceとは、scan(スキャン)、connect(接続)、disconnect(接続解除)などのWi-Fi操作を実行するためのWi-Fiインターフェースです.
Get interface information(インタフェース情報の取得):
一般的に、このプラットフォームにはWi-Fiインターフェースが1つしかありません.したがって、index 0を使用してWi-Fiインターフェースを取得します.
Pywifiは、ワイヤレスインタフェースを操作するためのプラットフォーム間Pythonモジュールを提供しています.
利点:使いやすい;WindowsとLinuxのサポート
1.Installation:
cd pywifi/
pip install .
Example:
import time
import pywifi
from pywifi import const
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.disconnect()
time.sleep(1)
assert iface.status() in\
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
profile = pywifi.Profile()
profile.ssid = 'testap'
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = '12345678'
iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
time.sleep(30)
assert iface.status() == const.IFACE_CONNECTED
iface.disconnect()
time.sleep(1)
assert iface.status() in\
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
2.Docmentation:
Constants(定数):
pywifiでは、以下のconstatnsが定義されています.
Interface Status(インタフェースのステータス):
Interface.status()は、次のstatus codeのいずれかを返します.
const.IFACE_DISCONNECTED
const.IFACE_SCANNING
const.IFACE_INACTIVE
const.IFACE_CONNECTING
const.IFACE_CONNECTED
Authentication Algorithms(認証アルゴリズム):
認証アルゴリズムはProfileファイルと一致する必要があります.一般的には、ほとんどのAPsがオープンアルゴリズムを使用しています.
const.AUTH_OPEN
const.AUTH_SHARED
KeyManagement Type(鍵管理タイプ)
鍵管理タイプはProfileに割り当てるべきです.普通のAPsの場合、
AP , Profile akm AKM_TYPE_NONE。
AP WPA , Profile akm AKM_TYUPE_WPAPSK。
AP WPA2 , Profile akm AKM_TYUPE_WPA2PSK。
企業APs使用AKM_TYPE_WPAとAKM_TYPE_WPA2.
const.AKM_TYPE_NONE
const.AKM_TYPE_WPA
const.AKM_TYPE_WPAPSK
const.AKM_TYPE_WPA2
const.AKM_TYPE_WPA2PSK
Cipher Type(パスワードタイプ):
akmがAKMじゃなかったらTYPE_NONEは、パスワードタイプをProfileに設定する必要があります.接続するAPの設定を参照してください.
const.CIPHER_TYPE_NONE
const.CIPHER_TYPE_WEP
const.CIPHER_TYPE_TKIP
const.CIPHER_TYPE_CCMP
Network Profile(ネットワークプロファイル):
Profileは、私たちが接続するAPの設定です.Profileのフィールド:
ssid - AP ssid。
auth - AP 。
akm - AP 。
cipher - AP 。
key (optinoal) -AP key( )。 CIPHER_TYPE_NONE, 。
Example:
import pywifi
profile = pywifi.Profile()
profile.ssid = 'testap'
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = '12345678'
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
profile = iface.add_network_profile(profile)
iface.connect(profile)
Interface(インタフェース)
Interfaceとは、scan(スキャン)、connect(接続)、disconnect(接続解除)などのWi-Fi操作を実行するためのWi-Fiインターフェースです.
Get interface information(インタフェース情報の取得):
一般的に、このプラットフォームにはWi-Fiインターフェースが1つしかありません.したがって、index 0を使用してWi-Fiインターフェースを取得します.
import pywifi
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
Interface.name() # wifi
Interface.scan() # APs
Interface.scan_results() # 。 Profile 。 。 Wi-Fi 。 scan() 2~8 scan_results() 。
Interface.add_network_profile(profile) # AP
Interface.remove_all_network_profiles() # AP
Interface.network_profiles() # Profile AP Profile
Interface.connect(profile) # profile AP。 , , connect(profile) add_network_profile(profile)
Interface.disconnect() # AP
Interface.status() # status status