def index(): form = IpForm() if request.method == "POST" and form.validate(): form = IpForm() ip = form.address.data if '/' in ip: return render_template("index.html", form=form, result=netmask(ip), ip=ip) elif ':' in ip: return render_template('index.html', form=form, result=is_valid_ipv6_address(ip), ip=ip) else: return render_template('index.html', form=form, result=is_valid_ipv4_address(ip), ip=ip) else: return render_template("index.html", form=form)
def validate_dns_servers_array(): for dns_server in configuration_variables.DNS_SERVERS_ARRAY: if not functions.is_valid_ipv4_address(dns_server) and not functions.is_valid_ipv6_address(dns_server): print("Invalid DNS server: " + dns_server) quit()
def validate_server_addresses_array(): for server_address in configuration_variables.SERVER_ADDRESSES_ARRAY: if not functions.is_valid_dns_name(server_address) and not functions.is_valid_ipv4_address(server_address)and not functions.is_valid_ipv6_address(server_address): print("Invalid address: " + server_address) print("It should be a DNS name, an IPv4 address or an IPv6 address.") quit()
def is_valid_ipv6_address(ipv6_address): return functions.is_valid_ipv6_address(ipv6_address)
def test_is_valid_ipv6_address(self): self.assertFalse(functions.is_valid_ipv6_address("example.com")) self.assertFalse(functions.is_valid_ipv6_address("example")) self.assertFalse(functions.is_valid_ipv6_address("localhost")) self.assertFalse( functions.is_valid_ipv6_address( "ex.exaple.example.example.example.example.example.example.com" )) self.assertFalse( functions.is_valid_ipv6_address( "example.example.example.example.example.example.example.example.com" )) self.assertFalse( functions.is_valid_ipv6_address( "ex.exa-ple.example.example.example.example.example.example.com" )) self.assertFalse( functions.is_valid_ipv6_address( "ex.-exa-ple.example.example.example.example.example.example.com" )) self.assertFalse( functions.is_valid_ipv6_address( "ex.exa-ple-.example.example.example.example.example.example.com" )) self.assertFalse(functions.is_valid_ipv6_address("127.0.0.1")) self.assertFalse(functions.is_valid_ipv6_address("127")) self.assertFalse(functions.is_valid_ipv6_address("127.0")) self.assertFalse(functions.is_valid_ipv6_address("127.0.0.1.0")) self.assertFalse(functions.is_valid_ipv6_address("-127.0.0.1")) self.assertFalse(functions.is_valid_ipv6_address("256.0.0.1")) self.assertTrue( functions.is_valid_ipv6_address("1234:abcd:1234:abcd:1234")) self.assertFalse(functions.is_valid_ipv6_address("1234")) self.assertFalse(functions.is_valid_ipv6_address("12ab")) self.assertFalse( functions.is_valid_ipv6_address("1234:abcd:1234:abcd:1234:abcd")) self.assertFalse( functions.is_valid_ipv6_address("1234:abcd:-1234:abcd:1234:abcd")) self.assertFalse( functions.is_valid_ipv6_address("1234:gbcd:1234:abcd:1234:abcd"))