示例#1
0
def resolve(host, mask=None):
    """resolve(hostname, [mask]
Resolve a hostname to an IPv4 object. An optional mask value may me supplied."""
    try:
        hostname, aliases, addresses = socket.gethostbyname_ex(str(host))
    except socket.gaierror, why:
        raise ValueError, "Unable to resolve host: %s" % (why[1])
示例#2
0
文件: ipv4.py 项目: wildone/pycopia
def resolve(host, mask=None):
    """Resolve a hostname to an IPv4 object. An optional mask value may me supplied."""
    try:
        hostname, aliases, addresses = socket.gethostbyname_ex(str(host))
    except socket.gaierror as why:
        raise ValueError("Unable to resolve host: %s" % (why[1]))
    if addresses:
        return IPv4(addresses[0], mask)
    else:
        raise ValueError("No addresses found.")
示例#3
0
def resolve(host, mask=None):
    """Resolve a hostname to an IPv4 object. An optional mask value may me supplied."""
    try:
        hostname, aliases, addresses = socket.gethostbyname_ex(str(host))
    except socket.gaierror as why:
        raise ValueError("Unable to resolve host: %s" % (why[1]))
    if addresses:
        return IPv4(addresses[0], mask)
    else:
        raise ValueError("No addresses found.")