def testConflict(ip1Param, ip2Param, netmaskParam, testSubnet=True): ipValue, netmaskValue = getIpNetmask(ip2Param, netmaskParam) if ipValue is not None: if ipValue == ip1Param.getValue(): return colorRed("SAME AS %s" % ip2Param.getName()) if testSubnet and netmaskValue is not None: if not check.checkIpsInSameSubnet(ipValue, ip1Param.getValue(), netmaskValue): netmaskInt = util.ipToInt(netmaskValue) ipPrefix = util.intToIp(util.ipToInt(ipValue) & netmaskInt) cidr = util.netmaskToCidr(netmaskValue) return colorRed("NOT IN SUBNET OF %s/%s" % (ipPrefix, cidr)) return None
def checkIp(ip): if ipRegex.match(ip) == None: return False ipInt = util.ipToInt(ip) if ipInt == 0: return False if (ipInt >> 24) == 127: return False return True
def checkIpsInSameSubnet(ip1, ip2, netmask): ip1Int = util.ipToInt(ip1) ip2Int = util.ipToInt(ip2) netmaskInt = util.ipToInt(netmask) return (ip1Int & netmaskInt) == (ip2Int & netmaskInt)
def checkNetmask(netmask): if ipRegex.match(netmask) == None: return False netmaskInt = util.ipToInt(netmask) return netmaskInt in validSubnets