(20250209) Subnet splitting example added.

This commit is contained in:
2025-02-09 17:25:24 +05:30
parent c6dce7ea59
commit 800d6706ef
2 changed files with 58 additions and 1 deletions
+57
View File
@@ -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())
+1 -1
View File
@@ -172,7 +172,7 @@ Hint: Walled-Garden IPs
"chain": "srcnat", "chain": "srcnat",
"disabled": "false", "disabled": "false",
"src-address": "100.65.0.16/28", "src-address": "100.65.0.16/28",
"to-addresses": "111.222.111.111" "to-addresses": "111.222.111.111" // Ask the /28 public IP
} }
``` ```