-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpcclient: add darwin_network for wifi scan
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from collections import namedtuple | ||
from typing import List | ||
|
||
from rpcclient.exceptions import RpcClientException | ||
from rpcclient.network import Network | ||
|
||
WifiNetwork = namedtuple('WifiNetwork', 'ssid bssid rssi') | ||
|
||
|
||
class DarwinNetwork(Network): | ||
def __init__(self, client): | ||
super().__init__(client) | ||
|
||
if 0 == client.dlopen('/System/Library/Frameworks/CoreWLAN.framework/Versions/A/CoreWLAN', 2): | ||
raise RpcClientException('failed to load CoreWLAN') | ||
|
||
def scan(self, iface: str) -> List[WifiNetwork]: | ||
""" perform wifi scan on selected interface """ | ||
result = [] | ||
CWInterface = self._client.symbols.objc_getClass('CWInterface') | ||
iface = CWInterface.objc_call('alloc').objc_call('initWithInterfaceName:', self._client.cf(iface)) | ||
networks = iface.objc_call('scanForNetworksWithName:error:', 0, 0).objc_call('allObjects') | ||
|
||
for i in range(networks.objc_call('count')): | ||
network = networks.objc_call('objectAtIndex:', i) | ||
result.append(WifiNetwork(ssid=network.objc_call('ssidData').py, bssid=network.objc_call('bssid').py, | ||
rssi=network.objc_call('rssiValue').c_int64)) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters