import socket


def _getIPAddressType(addr):
    """ Returns socket.AF_INET6 or socket.AF_INET4.
    May return false positives for ipv6 on windows """
    
    socketType = None
    
    # first see if this is a valid ipv4 addr
    try:
        socket.inet_aton(addr)
        socketType = socket.AF_INET
    except Exception as e:
        pass
    
    # hmm apparently not ipv4; lets try ipv6
    if socketType is None:
        try:
            # windows doesn't have inet_pton (at least prior to python 3.4);
            # ..in that case let's just assume its a valid v6 address if it
            # passes a rudimentary check
            if hasattr(socket, 'inet_pton'):
                socket.inet_pton(socket.AF_INET6, addr)
            else:
                # no inet_pton; just do a rudimentary check
                if ':' not in addr:
                    raise Exception('not an ipv6 address')
            socketType = socket.AF_INET6
        except Exception as e:
            pass
        
    if socketType is None:
        raise Exception("addr seems to be neither v4 or v6: "+str(addr))
    
    return socketType