コード例 #1
0
ファイル: netutils.py プロジェクト: ddonnelly19/dd-git
def getShortMask(netmask):
    """
    Returns the count of set bit in given network mask
    e.g. for mask '255.255.255.0' return value will be 24
    @type netmask: string
    @rtype: integer
    """
    shortMask = 0
    if IPv4.isValidIp(netmask):
        octets = netmask.split('.')
        for octet in octets:
            shortMask += getLeadingOnesCount(int(octet))
    return shortMask
コード例 #2
0
ファイル: netutils.py プロジェクト: deezeesms/dd-git
def getShortMask(netmask):
    """
    Returns the count of set bit in given network mask
    e.g. for mask '255.255.255.0' return value will be 24
    @type netmask: string
    @rtype: integer
    """
    shortMask = 0
    if IPv4.isValidIp(netmask):
        octets = netmask.split('.')
        for octet in octets:
            shortMask += getLeadingOnesCount(int(octet))
    return shortMask
コード例 #3
0
ファイル: netutils.py プロジェクト: ddonnelly19/dd-git
def isValidIp(ipAddr, filter_client_ip=None):
    """
    @deprecated: this method only supports IPv4,
                 use ip_addr.isValidIpAddress if you need IPv6 support

    Checks whether the given IP address is a valid IPv4 address.
    @param  ipAddr: IP address to check
    @type     ipAddr: string
    @return: true if the IP is valid IPv4 address, else false
    @rtype: Boolean
    """
    if ipAddr and filter_client_ip and DOMAIN_SCOPE_MANAGER.isClientIp(ipAddr):
        return None
    # in some cases windows machines report such IP address for DHCP Server
    # because of misconfiguration
    if ipAddr and ipAddr.strip() == '255.255.255.255':
        return None

    if ipAddr and ipAddr.strip() == '0.0.0.0':
        return None

    return IPv4.isValidIp(ipAddr)
コード例 #4
0
ファイル: netutils.py プロジェクト: deezeesms/dd-git
def isValidIp(ipAddr, filter_client_ip=None):
    """
    @deprecated: this method only supports IPv4,
                 use ip_addr.isValidIpAddress if you need IPv6 support

    Checks whether the given IP address is a valid IPv4 address.
    @param  ipAddr: IP address to check
    @type     ipAddr: string
    @return: true if the IP is valid IPv4 address, else false
    @rtype: Boolean
    """
    if ipAddr and filter_client_ip and DOMAIN_SCOPE_MANAGER.isClientIp(ipAddr):
        return None
    # in some cases windows machines report such IP address for DHCP Server
    # because of misconfiguration
    if ipAddr and ipAddr.strip() == '255.255.255.255':
        return None

    if ipAddr and ipAddr.strip() == '0.0.0.0':
        return None

    return IPv4.isValidIp(ipAddr)