Skip to content

Commit

Permalink
rpcclient: add darwin_network for wifi scan
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Feb 10, 2022
1 parent 2decf59 commit 9a0d000
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/rpcclient/rpcclient/client/darwin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rpcclient.client.client import Client
from rpcclient.darwin_fs import DarwinFs
from rpcclient.darwin_media import DarwinMedia
from rpcclient.darwin_network import DarwinNetwork
from rpcclient.darwin_processes import DarwinProcesses
from rpcclient.exceptions import RpcClientException
from rpcclient.preferences import Preferences
Expand Down Expand Up @@ -40,6 +41,7 @@ def __init__(self, sock, sysname: str, hostname: str, port: int = None):
self.prefs = Preferences(self)
self.processes = DarwinProcesses(self)
self.media = DarwinMedia(self)
self.network = DarwinNetwork(self)

@property
def modules(self) -> typing.List[str]:
Expand Down
29 changes: 29 additions & 0 deletions src/rpcclient/rpcclient/darwin_network.py
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
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def cfdesc(self):
"""
if self == 0:
return None
return self._client.symbols.CFCopyDescription(self).cfstr.peek_str()
return self._client.symbols.CFCopyDescription(self).py

@property
def py(self):
Expand Down

0 comments on commit 9a0d000

Please sign in to comment.