diff options
Diffstat (limited to 'cgi/manage.py')
-rw-r--r-- | cgi/manage.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/cgi/manage.py b/cgi/manage.py index 4ece445..f21e7e8 100644 --- a/cgi/manage.py +++ b/cgi/manage.py @@ -675,20 +675,29 @@ def manage(self, path_split): # Parse CIDR or IP glob try: - ipnetwork = netaddr.IPNetwork(ip) - ipstart, ipend = str(ipnetwork[0]), str(ipnetwork[-1]) - ipstr = str(ipnetwork) - except netaddr.core.AddrFormatError: - # Invalid format so try with globs - iprange = netaddr.glob_to_iprange(ip) - ipstart, ipend = str(iprange[0]), str(iprange[-1]) - - cidrs = iprange.cidrs() - if len(cidrs) == 1: - ipstr = str(cidrs[0]) + if netaddr.valid_ipv4(ip) or netaddr.valid_ipv6(ip): + ipaddress = netaddr.IPAddress(ip) + ipstart = ipend = ipstr = str(ipaddress) + elif netaddr.valid_glob(ip): + iprange = netaddr.glob_to_iprange(ip) + ipstart, ipend = str(iprange[0]), str(iprange[-1]) + + cidrs = iprange.cidrs() + if len(cidrs) == 1: + ipstr = str(cidrs[0]) + else: + ipstr = str(iprange) + elif '/' in ip: + # Try with CIDR + ipnetwork = netaddr.IPNetwork(ip) + ipstart, ipend = str(ipnetwork[0]), str(ipnetwork[-1]) + ipstr = str(ipnetwork) else: - ipstr = str(iprange) - + self.error("IP o rango inválido.") + return + except netaddr.core.AddrFormatError, e: + self.error("Problema con el IP o rango ingresado: {}".format(e)) + return if self.formdata['seconds'] != '0': until = str( |