Compare commits

...

2 Commits

Author SHA1 Message Date
74e7d6de64 chore: add test data 2025-10-04 22:34:48 +01:00
8ea8954710 feat: add multiple records in one request 2025-10-04 22:34:39 +01:00

35
main.py
View File

@@ -17,15 +17,22 @@ router = AsusRouter(
use_ssl=credentials.get('use_ssl', False)
)
async def main(rule_name):
# Start connection to router
existing_rules = []
new_rules = []
async def main(rule_tag, new_ip):
global existing_rules
global new_rules
await router.async_connect()
# Get port forwarding rules
pfwd = await router.async_get_data(AsusData.PORT_FORWARDING)
# Store existing rules that match tag
for rule in pfwd['rules']:
if(rule_name in rule.name):
rules = [
if rule_tag in rule.name:
existing_rules += [
PortForwardingRule(
name=rule.name,
ip_address=rule.ip_address,
@@ -35,12 +42,22 @@ async def main(rule_name):
port_external=rule.port_external
)
]
result = await router.async_remove_port_forwarding_rules(rules=rules)
print(result)
new_rules += [
PortForwardingRule(
name=rule.name,
ip_address=rule.ip_address,
port=rule.port,
protocol=rule.protocol,
ip_external=new_ip,
port_external=rule.port_external
)
]
result = await router.async_set_port_forwarding_rules(new_rules)
if result:
print("New records set.")
# End connection to router
await router.async_disconnect()
if __name__ == "__main__":
asyncio.run(main(""))
asyncio.run(main("TEST", "192.168.1.2"))