Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter and defaults to network scan #8

Merged
merged 2 commits into from
Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions googledevices/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
author_email="[email protected]",
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(),
Expand Down