Advertisement
Guest User

Untitled

a guest
Jan 30th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. from ipaddress import ip_address, ip_network
  2.  
  3. allowed_networks = [
  4.     "10.255.255.0/24",
  5.     "10.254.254.0/25",
  6. ]
  7.  
  8. def is_ip_allowed(client_ip):
  9.     try:
  10.         ip = ip_address(client_ip)
  11.         for network in allowed_networks:
  12.             if ip in ip_network(network):
  13.                 return True
  14.     except ValueError:
  15.         return False
  16.     return False
  17.  
  18. client_ip = ak_client_ip
  19.  
  20. return is_ip_allowed(client_ip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement