Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
def checkIpsInSameSubnet(ip1, ip2, netmask):
    ip1Int = util.ipToInt(ip1)
    ip2Int = util.ipToInt(ip2)
    netmaskInt = util.ipToInt(netmask)
    return (ip1Int & netmaskInt) == (ip2Int & netmaskInt)
Esempio n. 5
0
def checkNetmask(netmask):
    if ipRegex.match(netmask) == None:
        return False

    netmaskInt = util.ipToInt(netmask)
    return netmaskInt in validSubnets
Esempio n. 6
0
def checkIpsInSameSubnet(ip1, ip2, netmask):
    ip1Int = util.ipToInt(ip1)
    ip2Int = util.ipToInt(ip2)
    netmaskInt = util.ipToInt(netmask)
    return (ip1Int & netmaskInt) == (ip2Int & netmaskInt)
Esempio n. 7
0
def checkNetmask(netmask):
    if ipRegex.match(netmask) == None:
        return False

    netmaskInt = util.ipToInt(netmask)
    return netmaskInt in validSubnets