diff --git a/googledevices/cli/commands.py b/googledevices/cli/commands.py index 2655914..6be6c26 100644 --- a/googledevices/cli/commands.py +++ b/googledevices/cli/commands.py @@ -46,17 +46,35 @@ async def get_device_info(): @scan_network_group.command() -@click.argument('subnet', required=1) -def scan_network(subnet): +@click.option('--network', '-N', type=str, default=None, + help="The network you want to scan\ + in this format '192.168.1.0/24'.") +@click.option('--feature', '-F', type=str, default=None, + help="Filter discovery result to\ + units that contain these feature.") +def scan_network(network, feature): """Scan the entire subnet for Google devices.""" from googledevices.utils.scan import NetworkScan async def get_all_units(): - """Get device info from GH.""" + """Get device info for all Google devices.""" + all_devices = [] + if network is None: + import netifaces + gateway = netifaces.gateways() + subnet = gateway['default'][netifaces.AF_INET][0][:-1] + '0/24' + else: + subnet = network async with aiohttp.ClientSession() as session: googledevices = NetworkScan(LOOP, session) result = await googledevices.scan_for_units(subnet) - print(json.dumps(result, indent=4, sort_keys=True)) + if feature: + for unit in result: + if unit[feature]: + all_devices.append(unit) + else: + all_devices = result + print(json.dumps(all_devices, indent=4, sort_keys=True)) LOOP.run_until_complete(get_all_units()) diff --git a/setup.py b/setup.py index 371fd07..3ca6a43 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ author_email="ludeeus@gmail.com", description="", long_description=LONG, - install_requires=['aiohttp', 'async_timeout', 'click'], + install_requires=['aiohttp', 'async_timeout', 'click', 'netifaces'], long_description_content_type="text/markdown", url="https://github.com/ludeeus/googledevices", packages=setuptools.find_packages(),