diff --git a/playground/mikrotik/subnet_split.py b/playground/mikrotik/subnet_split.py new file mode 100644 index 0000000..d34ed7f --- /dev/null +++ b/playground/mikrotik/subnet_split.py @@ -0,0 +1,57 @@ +from netaddr import IPNetwork +from utils_v2.string import json + +src_network = IPNetwork("100.64.0.0/24") +src_subnets = list(src_network.subnet(28)) +print("SUBNET:", json.to_string(src_subnets, default=str)) +print("COUNT:", len(src_subnets)) + + +dst_network = IPNetwork("100.127.0.0/28") +dst_subnets = list(dst_network.subnet(32)) +print("SUBNET:", json.to_string(dst_subnets, default=str)) +print("COUNT:", len(dst_subnets)) + + +final_json = [ + { + "action": "src-nat", + "chain": "srcnat", + "disabled": "false", + "src-address": str(i[0]), + "to-addresses": str(i[1]) + } for i in zip(src_subnets, dst_subnets) +] +print("SUBNET:", json.to_string(final_json, default=str)) + +import asyncio +import httpx + +http_client = httpx.AsyncClient( + limits = httpx.Limits( + max_connections = 100, # ............ Maximum number of connections allowed in the pool. + max_keepalive_connections = 50, # ... Maximum number of connections that can be kept alive. + ), + timeout = httpx.Timeout( + pool = 120.0, # .... Time to wait for a free connection from the pool. + connect = 2.5, # ... Time to wait for establishing a connection to the server. + write = 10.0, # .... Time to wait for sending data. + read = 9.9 # ....... Time to wait for receiving data. + ) +) + + +async def configure_nat(): + + tasks = [ + http_client.put( + url = r"http://102.210.175.251/rest/ip/firewall/nat", + auth = httpx.BasicAuth(username = "easyfi", password = "easyfi"), + json = i + ) for i in final_json + ] + print("Async NAT") + results = await asyncio.gather(*tasks) + print(results) + +# asyncio.run(configure_nat()) diff --git a/readme/Mikrotik - EasyFi.md b/readme/Mikrotik - EasyFi.md index e7694b2..f8999ed 100644 --- a/readme/Mikrotik - EasyFi.md +++ b/readme/Mikrotik - EasyFi.md @@ -172,7 +172,7 @@ Hint: Walled-Garden IPs "chain": "srcnat", "disabled": "false", "src-address": "100.65.0.16/28", - "to-addresses": "111.222.111.111" + "to-addresses": "111.222.111.111" // Ask the /28 public IP } ```