def test_ip_and_subnet_and_range(self): subnets = ['10.0.0.10', '10.0.0.0/24', '10.0.0.252-10.0.0.253'] result = [ ('10.0.0.10', '10.0.0.0/24', IPSet(['10.0.0.10/32'])), ('10.0.0.0/24', '10.0.0.252-10.0.0.253', IPSet(['10.0.0.252/31'])), ] self.assertEqual(check_conflicts(subnets), result)
def test_ips_and_subnet(self): subnets = ['10.0.0.1', '10.0.0.2', '10.0.0.0/24'] result = [ ('10.0.0.1', '10.0.0.0/24', IPSet(['10.0.0.1/32'])), ('10.0.0.2', '10.0.0.0/24', IPSet(['10.0.0.2/32'])), ] self.assertEqual(check_conflicts(subnets), result)
def test_two_ranges(self): subnets = ['10.0.0.1-10.0.0.5', '10.0.0.3-10.0.0.10'] result = [ ('10.0.0.1-10.0.0.5', '10.0.0.3-10.0.0.10', IPSet(['10.0.0.3/32', '10.0.0.4/32', '10.0.0.5/32'])), ] self.assertEqual(check_conflicts(subnets), result)
def main(): parser = argparse.ArgumentParser( description=u'Check for conflicts between subnets.', epilog=epilog, formatter_class=argparse.RawTextHelpFormatter, ) parser.add_argument('subnets', nargs='*', help=u'list of subnets to be checked') parser.add_argument( '-f', '--from-file', default='', help=u'load subnet definitions from file (one per line)') parser.add_argument('-i', '--from-stdin', action='store_true', help=u'load subnet definitions from stdin') parser.add_argument('-o', '--ip-only', action='store_true', help=u'print only the overlapping IP addresses') parser.add_argument('-p', '--print-conflicts', action='store_true', help=u'print overlapping IP addresses') parser.add_argument('-V', '--version', action='store_true', help=u'print ipconflict version') args = parser.parse_args(sys.argv[1:]) if not args: parser.print_usage() sys.exit(0) if args.version: print(u'ipconflict {}'.format(version)) sys.exit(0) subnets = args.subnets if args.from_stdin: subnets += parse_stdin_data() subnet_file = args.from_file if subnet_file: subnets += parse_subnet_file(subnet_file) if len(subnets) < 2: print('must specify at least 2 subnets') sys.exit(1) conflicts = check_conflicts(subnets) print_results(conflicts, args.print_conflicts, args.ip_only)
def test_two_ips(self): subnets = ['10.0.0.1', '10.0.0.2'] self.assertEqual(check_conflicts(subnets), [])
def test_subnet_and_range(self): subnets = ['10.0.0.0/24', '10.0.0.5-10.0.0.6'] result = [('10.0.0.0/24', '10.0.0.5-10.0.0.6', IPSet(['10.0.0.5/32', '10.0.0.6/32']))] self.assertEqual(check_conflicts(subnets), result)
def test_ip_and_range(self): subnets = ['10.0.0.3', '10.0.0.1-10.0.0.254'] result = [('10.0.0.3', '10.0.0.1-10.0.0.254', IPSet(['10.0.0.3/32']))] self.assertEqual(check_conflicts(subnets), result)
def test_two_subnets(self): subnets = ['10.0.1.0/24', '10.0.0.0/22'] result = [('10.0.1.0/24', '10.0.0.0/22', IPSet(['10.0.1.0/24']))] self.assertEqual(check_conflicts(subnets), result)
def test_two_ips(self): subnets = ['10.0.0.1', '10.0.0.1'] result = [('10.0.0.1', '10.0.0.1', IPSet(['10.0.0.1/32']))] self.assertEqual(check_conflicts(subnets), result)
def test_multiple_types(self): subnets = ['10.0.0.1', '172.16.0.1/24', '192.168.0.1-192.168.0.254'] self.assertEqual(check_conflicts(subnets), [])
def test_multiple_ranges(self): subnets = [ '10.0.0.10-10.0.0.20', '10.0.0.30-10.0.0.40', '10.0.0.50-10.0.0.60' ] self.assertEqual(check_conflicts(subnets), [])
def test_multiple_subnets(self): subnets = ['10.0.0.0/24', '10.0.1.0/24', '10.0.2.0/24'] self.assertEqual(check_conflicts(subnets), [])
def test_multiple_ips(self): subnets = ['10.0.0.1', '10.0.0.2', '10.0.0.3'] self.assertEqual(check_conflicts(subnets), [])