47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
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(""))
|
|
|