diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fa45c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config_modem.py +__pycache__ diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config_modem.py.dist b/config_modem.py.dist new file mode 100644 index 0000000..488c14d --- /dev/null +++ b/config_modem.py.dist @@ -0,0 +1,25 @@ +from sagemcom_api.enums import EncryptionMethod +from sagemcom_api.client import SagemcomClient +import json + +HOST = '192.168.2.1' +USERNAME = 'admin' +PASSWORD = '' +ENCRYPTION_METHOD = EncryptionMethod.SHA512 # EncryptionMethod.MD5 or EncryptionMethod.SHA512 +SSL = True +WIFI_RADIOS = ['RADIO2G4', 'RADIO5G', 'RADIO6G'] +ADMZ_MAC = '' + + +async def modem() -> SagemcomClient: + return SagemcomClient( + host = HOST, + username = USERNAME, + password = PASSWORD, + authentication_method = ENCRYPTION_METHOD, + ssl = SSL, + keep_keys = True, + ) + +def dump(value) -> str: + print(json.dumps(value, indent = 2)) diff --git a/disable_wifi.py b/disable_wifi.py new file mode 100755 index 0000000..bd9de8e --- /dev/null +++ b/disable_wifi.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +import asyncio +from sagemcom_api.client import SagemcomClient +from modem_config import * + +async def main() -> None: + async with await modem() as client: + try: + await client.login() + + except Exception as exception: # pylint: disable=broad-except + print(exception) + return + + for radio in WIFI_RADIOS: + await client.set_value_by_xpath("Device/WiFi/Radios/Radio[Alias='" + radio + "']/Enable", False) + +asyncio.run(main()) diff --git a/example.py b/example.py new file mode 100644 index 0000000..c1c5be5 --- /dev/null +++ b/example.py @@ -0,0 +1,33 @@ +import asyncio +from sagemcom_api.client import SagemcomClient +from config_modem import * + +async def main() -> None: + async with await modem() as client: + try: + await client.login() + + except Exception as exception: # pylint: disable=broad-except + print(exception) + return + + # Print device information of Sagemcom F@st router +# device_info = await client.get_device_info() +# print(f"{device_info.id} {device_info.model_name}") + + # Print connected devices +# devices = await client.get_hosts() + +# for device in devices: +# if device.active: +# print(f"{device.id} - {device.name}") + + # Retrieve values via XPath notation, output is a dict + custom_command_output = await client.get_value_by_xpath('Device/Services/BellNetworkCfg') + + dump(custom_command_output) + +# await client.set_value_by_xpath("Device/Services/BellNetworkCfg/SetBridgeMode", "on") + + +asyncio.run(main()) diff --git a/fix_admz.py b/fix_admz.py new file mode 100755 index 0000000..0adbb41 --- /dev/null +++ b/fix_admz.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 +import asyncio +from sagemcom_api.client import SagemcomClient +from modem_config import * + +async def main() -> None: + async with await modem() as client: + try: + await client.login() + + except Exception as exception: # pylint: disable=broad-except + print(exception) + return + + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', False) + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/AdvancedDMZhost', ADMZ_MAC) + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', True) + +asyncio.run(main()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4c45e40 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +git+https://github.com/djGrrr/python-sagemcom-api.git@master#egg=sagemcom_api diff --git a/set_voice_wan_modes.py b/set_voice_wan_modes.py new file mode 100755 index 0000000..3bc2e2b --- /dev/null +++ b/set_voice_wan_modes.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 +import asyncio +from sagemcom_api.client import SagemcomClient +from modem_config import * + +async def main() -> None: + async with await modem() as client: + try: + await client.login() + + except Exception as exception: # pylint: disable=broad-except + print(exception) + return + + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/VoiceAllowedWANModes', 'ftth,gpon,xgspon') + +asyncio.run(main())