commit 633d87fb65e6f3f34f66e21fb53e890f9064a5b1 Author: Jordan Walster Date: Sat Oct 4 19:21:06 2025 +0100 chore: initial commit diff --git a/auth.yml b/auth.yml new file mode 100644 index 0000000..e2767ab --- /dev/null +++ b/auth.yml @@ -0,0 +1,5 @@ +credentials: + ip: 192.168.1.1 + user: admin + password: changeme + use_ssl: true diff --git a/main.py b/main.py new file mode 100644 index 0000000..ca0396a --- /dev/null +++ b/main.py @@ -0,0 +1,46 @@ +import asyncio +import yaml + +from asusrouter import AsusRouter, AsusData +from asusrouter.modules.port_forwarding import PortForwardingRule + +with open("credentials.yml") as stream: + try: + credentials = yaml.safe_load(stream)['credentials'] + except yaml.YAMLError as exc: + print(exc) + +router = AsusRouter( + hostname=credentials.get('ip'), + username=credentials.get('user'), + password=credentials.get('password'), + use_ssl=credentials.get('use_ssl', False) +) + +async def main(rule_name): + # Start connection to router + await router.async_connect() + # Get port forwarding rules + pfwd = await router.async_get_data(AsusData.PORT_FORWARDING) + + for rule in pfwd['rules']: + if(rule_name in rule.name): + rules = [ + PortForwardingRule( + name=rule.name, + ip_address=rule.ip_address, + port=rule.port, + protocol=rule.protocol, + ip_external=rule.ip_external, + port_external=rule.port_external + ) + ] + result = await router.async_remove_port_forwarding_rules(rules=rules) + print(result) + + # End connection to router + await router.async_disconnect() + +if __name__ == "__main__": + asyncio.run(main("")) +