def test_calculate_broadcast_address_from_ip_and_netmask(self):
        known_correct_values = [(('192.168.1.0', '255.255.255.0'), '192.168.1.255'),
                                (('192.168.0.0', '255.255.0.0'),   '192.168.255.255'),
                                (('192.0.0.0', '255.0.0.0'),       '192.255.255.255'),
                                (('192.160.1.0', '255.242.255.0'), '192.173.1.255'),
                                (('0.168.1.0', '0.255.255.0'),   '255.168.1.255')]

        for ((ip, netmask), expected_bcast) in known_correct_values:
            numip               = network.dotted_to_numeric_ip(ip)
            numnetmask          = network.dotted_to_numeric_ip(netmask)
            guessed_broadcast   = network.calculate_broadcast_address_from_ip_and_netmask(numip, numnetmask)
            self.assertEqual(guessed_broadcast,
                             network.dotted_to_numeric_ip(expected_bcast),
                             "%s %s made %s, but expected %s" % (ip,
                                                                 netmask,
                                                                 network.numeric_to_dotted_ip(guessed_broadcast),
                                                                 expected_bcast))
Esempio n. 2
0
    def test_calculate_broadcast_address_from_ip_and_netmask(self):
        known_correct_values = [
            (('192.168.1.0', '255.255.255.0'), '192.168.1.255'),
            (('192.168.0.0', '255.255.0.0'), '192.168.255.255'),
            (('192.0.0.0', '255.0.0.0'), '192.255.255.255'),
            (('192.160.1.0', '255.242.255.0'), '192.173.1.255'),
            (('0.168.1.0', '0.255.255.0'), '255.168.1.255')
        ]

        for ((ip, netmask), expected_bcast) in known_correct_values:
            numip = network.dotted_to_numeric_ip(ip)
            numnetmask = network.dotted_to_numeric_ip(netmask)
            guessed_broadcast = network.calculate_broadcast_address_from_ip_and_netmask(
                numip, numnetmask)
            self.assertEqual(
                guessed_broadcast,
                network.dotted_to_numeric_ip(expected_bcast),
                "%s %s made %s, but expected %s" %
                (ip, netmask, network.numeric_to_dotted_ip(guessed_broadcast),
                 expected_bcast))
 def test_ip_conversion(self):
     for x in xrange(256*256):
         self.assertEqual(x*x, network.dotted_to_numeric_ip(network.numeric_to_dotted_ip(x*x)))
Esempio n. 4
0
 def test_ip_conversion(self):
     for x in xrange(256 * 256):
         self.assertEqual(
             x * x,
             network.dotted_to_numeric_ip(
                 network.numeric_to_dotted_ip(x * x)))