mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-24 21:08:30 +00:00
perf: 修改过滤的 q
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import ipaddress
|
||||
import socket
|
||||
from ipaddress import ip_network, ip_address
|
||||
|
||||
@@ -75,6 +76,23 @@ def contains_ip(ip, ip_group):
|
||||
return False
|
||||
|
||||
|
||||
def is_ip(self, ip, rule_value):
|
||||
if rule_value == '*':
|
||||
return True
|
||||
elif '/' in rule_value:
|
||||
network = ipaddress.ip_network(rule_value)
|
||||
return ip in network.hosts()
|
||||
elif '-' in rule_value:
|
||||
start_ip, end_ip = rule_value.split('-')
|
||||
start_ip = ipaddress.ip_address(start_ip)
|
||||
end_ip = ipaddress.ip_address(end_ip)
|
||||
return start_ip <= ip <= end_ip
|
||||
elif len(rule_value.split('.')) == 4:
|
||||
return ip == rule_value
|
||||
else:
|
||||
return ip.startswith(rule_value)
|
||||
|
||||
|
||||
def get_ip_city(ip):
|
||||
if not ip or not isinstance(ip, str):
|
||||
return _("Invalid address")
|
||||
|
Reference in New Issue
Block a user