Beispiel #1
0
    def test_ipv4_addr(self):
        '''
        Test IPv4 address validation
        '''
        true_addrs = [
            '127.0.0.1',
            '127.0.0.1',
            '127.0.0.19',
            '1.1.1.1/28',
            '127.0.0.11/32',
        ]

        false_addrs = [
            '127.0.0.911',
            '127.0.0911',
            '127.0.011',
            '127.0.011/32',
            '::1',
            '::1/128',
            '::1/28',
        ]

        for addr in true_addrs:
            self.assertTrue(net.ipv4_addr(addr))

        for addr in false_addrs:
            self.assertFalse(net.ipv4_addr(addr))
Beispiel #2
0
    def test_ipv4_addr(self):
        """
        Test IPv4 address validation
        """
        true_addrs = [
            "127.0.0.1",
            "127.0.0.1",
            "127.0.0.19",
            "1.1.1.1/28",
            "127.0.0.11/32",
        ]

        false_addrs = [
            "127.0.0.911",
            "127.0.0911",
            "127.0.011",
            "127.0.011/32",
            "::1",
            "::1/128",
            "::1/28",
        ]

        for addr in true_addrs:
            self.assertTrue(net.ipv4_addr(addr))

        for addr in false_addrs:
            self.assertFalse(net.ipv4_addr(addr))
Beispiel #3
0
    def test_ipv4_addr(self):
        '''
        Test IPv4 address validation
        '''
        true_addrs = [
            '127.0.0.1',
            '127.0.0.1',
            '127.0.0.19',
            '1.1.1.1/28',
            '127.0.0.11/32',
        ]

        false_addrs = [
            '127.0.0.911',
            '127.0.0911',
            '127.0.011',
            '127.0.011/32',
            '::1',
            '::1/128',
            '::1/28',
        ]

        for addr in true_addrs:
            self.assertTrue(net.ipv4_addr(addr))

        for addr in false_addrs:
            self.assertFalse(net.ipv4_addr(addr))
Beispiel #4
0
def clean_bind(addr):
    '''
    Splits a bind address on ':', and checks each part to make sure it is either
    a valid port (an int) or a valid IPv4 address. This is more for sanitization
    purposes than for validity checking.

    SSH options that will use this are -b, -D, -L, -R and -W
    '''
    comps = addr.split()
    for part in comps:
        try:
            int(part)
            if not suvn.ipv4_addr(part):
                return False
        except ValueError:
            return False
    return True
Beispiel #5
0
def _net_mask(combined):
    if "/" in combined:
        addr, netmask = combined.split('/', 1)
    else:
        addr, netmask = combined, "255.255.255.255"

    if not nw_validate.ipv4_addr(addr):
       raise TypeError('not a valid ipv4 address: {0}'.format(addr))
       addr = None
    else:
        if not nw_validate.netmask(netmask):
            netmask = nw.cidr_to_ipv4_netmask(netmask)
        if not nw_validate.netmask(netmask):
            raise TypeError('not a valid (neither 4x ".", nor CIDR) ipv4 netmask: {0}'.format(netmask))
            netmask = None

    return addr, netmask
    def test_ipv4_addr(self):
        """
        Test IPv4 address validation
        """
        self.assertTrue(net.ipv4_addr("127.0.0.1"))
        self.assertTrue(net.ipv4_addr("127.0.0.1"))
        self.assertTrue(net.ipv4_addr("127.0.0.19"))
        self.assertTrue(net.ipv4_addr("1.1.1.1/28"))
        self.assertTrue(net.ipv4_addr("127.0.0.11/32"))

        self.assertFalse(net.ipv4_addr("127.0.0.911"))
        self.assertFalse(net.ipv4_addr("127.0.0911"))
        self.assertFalse(net.ipv4_addr("127.0.011"))
        self.assertFalse(net.ipv4_addr("127.0.011/32"))
        self.assertFalse(net.ipv4_addr("::1"))
        self.assertFalse(net.ipv4_addr("::1/128"))
        self.assertFalse(net.ipv4_addr("::1/28"))
Beispiel #7
0
    def test_ipv4_addr(self):
        '''
        Test IPv4 address validation
        '''
        self.assertTrue(net.ipv4_addr('127.0.0.1'))
        self.assertTrue(net.ipv4_addr('127.0.0.1'))
        self.assertTrue(net.ipv4_addr('127.0.0.19'))
        self.assertTrue(net.ipv4_addr('1.1.1.1/28'))
        self.assertTrue(net.ipv4_addr('127.0.0.11/32'))

        self.assertFalse(net.ipv4_addr('127.0.0.911'))
        self.assertFalse(net.ipv4_addr('127.0.0911'))
        self.assertFalse(net.ipv4_addr('127.0.011'))
        self.assertFalse(net.ipv4_addr('127.0.011/32'))
        self.assertFalse(net.ipv4_addr('::1'))
        self.assertFalse(net.ipv4_addr('::1/128'))
        self.assertFalse(net.ipv4_addr('::1/28'))