/usr/lib/python2.7/dist-packages/pyroute2/iwutil.py is in python-pyroute2 0.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | '''
IW module
=========
Experimental module
'''
from pyroute2.netlink import NLM_F_REQUEST
from pyroute2.netlink import NLM_F_DUMP
from pyroute2.netlink.nl80211 import NL80211
from pyroute2.netlink.nl80211 import nl80211cmd
from pyroute2.netlink.nl80211 import NL80211_NAMES
class IW(NL80211):
def __init__(self, *argv, **kwarg):
# get specific groups kwarg
if 'groups' in kwarg:
groups = kwarg['groups']
del kwarg['groups']
else:
groups = None
# get specific async kwarg
if 'async' in kwarg:
async = kwarg['async']
del kwarg['async']
else:
async = False
# align groups with async
if groups is None:
groups = ~0 if async else 0
# continue with init
super(IW, self).__init__(*argv, **kwarg)
# do automatic bind
# FIXME: unfortunately we can not omit it here
self.bind(groups, async)
def list_wiphy(self):
'''
Get all list of phy device
'''
msg = nl80211cmd()
msg['cmd'] = NL80211_NAMES['NL80211_CMD_GET_WIPHY']
return self.nlm_request(msg,
msg_type=self.prid,
msg_flags=NLM_F_REQUEST | NLM_F_DUMP)
def get_interface_by_phy(self, attr):
'''
Get interface by phy name ( use x.get_attr('NL80211_ATTR_WIPHY') )
'''
msg = nl80211cmd()
msg['cmd'] = NL80211_NAMES['NL80211_CMD_GET_INTERFACE']
msg['attrs'] = [['NL80211_ATTR_WIPHY', attr]]
return self.nlm_request(msg,
msg_type=self.prid,
msg_flags=NLM_F_REQUEST | NLM_F_DUMP)
def get_interface_by_ifindex(self, ifindex):
'''
Get interface by ifindex ( use x.get_attr('NL80211_ATTR_IFINDEX')
'''
msg = nl80211cmd()
msg['cmd'] = NL80211_NAMES['NL80211_CMD_GET_INTERFACE']
msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]]
return self.nlm_request(msg,
msg_type=self.prid,
msg_flags=NLM_F_REQUEST)
def connect(self, ifindex, ssid, bssid=None):
'''
Connect to the ap with ssid and bssid
Warn: Use of put because message does return nothing,
Use this function with the good right (Root or may be setcap )
'''
msg = nl80211cmd()
msg['cmd'] = NL80211_NAMES['NL80211_CMD_CONNECT']
msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex],
['NL80211_ATTR_SSID', ssid]]
if bssid is not None:
msg['attrs'].append(['NL80211_ATTR_MAC', bssid])
self.put(msg, msg_type=self.prid, msg_flags=NLM_F_REQUEST)
def disconnect(self, ifindex):
'''
Disconnect the device
'''
msg = nl80211cmd()
msg['cmd'] = NL80211_NAMES['NL80211_CMD_DISCONNECT']
msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]]
self.put(msg, msg_type=self.prid, msg_flags=NLM_F_REQUEST)
def scan(self, ifindex):
'''
Scan wifi
'''
msg = nl80211cmd()
msg['cmd'] = NL80211_NAMES['NL80211_CMD_TRIGGER_SCAN']
msg['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]]
self.put(msg, msg_type=self.prid,
msg_flags=NLM_F_REQUEST)
scanResultNotFound = True
while scanResultNotFound:
listMsg = self.get()
for msg in listMsg:
if msg["event"] == "NL80211_CMD_NEW_SCAN_RESULTS":
scanResultNotFound = False
break
msg2 = nl80211cmd()
msg2['cmd'] = NL80211_NAMES['NL80211_CMD_GET_SCAN']
msg2['attrs'] = [['NL80211_ATTR_IFINDEX', ifindex]]
return self.nlm_request(msg2, msg_type=self.prid,
msg_flags=NLM_F_REQUEST | NLM_F_DUMP)
|