Add some useful scripts

This commit is contained in:
djGrrr
2023-03-05 22:24:19 -03:30
parent 469a3893b8
commit 6eee6066e0
8 changed files with 115 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
config_modem.py
__pycache__
View File
+25
View File
@@ -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))
+18
View File
@@ -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())
+33
View File
@@ -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())
Executable
+19
View File
@@ -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())
+1
View File
@@ -0,0 +1 @@
git+https://github.com/djGrrr/python-sagemcom-api.git@master#egg=sagemcom_api
+17
View File
@@ -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())