当前位置: 首页>>代码示例>>Python>>正文


Python socket.inet_aton方法代码示例

本文整理汇总了Python中socket.inet_aton方法的典型用法代码示例。如果您正苦于以下问题:Python socket.inet_aton方法的具体用法?Python socket.inet_aton怎么用?Python socket.inet_aton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket的用法示例。


在下文中一共展示了socket.inet_aton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: maxIpaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def maxIpaddr(ipaddr, netmask):
    """
        Takes a quad dot format IP address string and makes it the largest valid value still in the same subnet.

        Returns:
            Max quad dot IP string or None if error
    """
    try:
        val = struct.unpack("!I", socket.inet_aton(ipaddr))[0]
        nm = struct.unpack("!I", socket.inet_aton(netmask))[0]
        inc = struct.unpack("!I", socket.inet_aton("0.0.0.254"))[0]
        val &= nm
        val |= inc
        return socket.inet_ntoa(struct.pack('!I', val))
    except Exception:
        return None 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:18,代码来源:addresses.py

示例2: is_valid_cidr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:utils.py

示例3: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def __init__(self,fields):
		if fields == None:
			self.source = None
			self.dest = None
			self.timestamp = None
			self.size = 0
			self.key = None
		else:
			self.source = socket.inet_aton(fields[0])
			self.dest = socket.inet_aton(fields[1])
			self.timestamp = float(fields[2])
			self.size = int(fields[3])
			if self.source < self.dest:
				self.key = self.source + self.dest
			else:
				self.key = self.dest + self.source 
开发者ID:pratiknarang,项目名称:peershark,代码行数:18,代码来源:Packet.py

示例4: inet_pton

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def inet_pton(_, host):
            return socket.inet_aton(host)


# A secure default.
# Sources for more information on TLS ciphers:
#
# - https://wiki.mozilla.org/Security/Server_Side_TLS
# - https://www.ssllabs.com/projects/best-practices/index.html
# - https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
#
# The general intent is:
# - Prefer TLS 1.3 cipher suites
# - prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE),
# - prefer ECDHE over DHE for better performance,
# - prefer any AES-GCM and ChaCha20 over any AES-CBC for better performance and
#   security,
# - prefer AES-GCM over ChaCha20 because hardware-accelerated AES is common,
# - disable NULL authentication, MD5 MACs and DSS for security reasons. 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:21,代码来源:ssl_.py

示例5: is_valid_cidr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
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 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:24,代码来源:utils.py

示例6: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def __init__(self, name, host):
        self.__clientKey = None
        self.__macAddress = None
        self.__name = name
        self.__handshake_done = False

        # Check if host is an IP address or hostname
        # Try to resolve the hostname
        try:
            socket.inet_aton(host)
            self.__ip = host
            self.__hostname = socket.gethostbyaddr(host)[0]
        except:
            self.__hostname = host
            self.__ip = socket.gethostbyname(host)

        if self.__macAddress is None and self.__ip is not None:
            self.__macAddress = self.__get_mac_address(self.__ip)

        super(LGTVAuth, self).__init__('ws://' + self.__ip + ':3000/', exclude_headers=["Origin"])
        self.__waiting_callback = self.__prompt 
开发者ID:klattimer,项目名称:LGWebOSRemote,代码行数:23,代码来源:auth.py

示例7: _create_ipv4_sockets

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def _create_ipv4_sockets(loopback_enabled):
    # Open a multicast send socket, with IP_MULTICAST_LOOP enabled or disabled as requested.
    mcast_address = "224.0.1.195"
    port = 49501
    group = (mcast_address, port)
    txsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    txsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    if loopback_enabled:
        txsock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1)
    else:
        txsock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 0)
    txsock.connect(group)
    # Open a multicast receive socket and join the group
    rxsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    req = struct.pack("=4sl", socket.inet_aton(mcast_address), socket.INADDR_ANY)
    rxsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, req)
    rxsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    rxsock.bind(group)
    return (txsock, rxsock) 
开发者ID:brunorijsman,项目名称:rift-python,代码行数:21,代码来源:multicast_checks.py

示例8: consume

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def consume(self, doc, _):
    """
    Find entities in documents matching compiled regular expression.

    :param doc: Document object.
    :type doc: ``gransk.core.document.Document``
    """
    if not doc.text:
      return

    entities = doc.entities

    for result in self.pattern.finditer(doc.text):
      entity_value = result.group(result.lastgroup)

      if result.lastgroup == 'ip_addr':
        try:
          socket.inet_aton(entity_value)
        except socket.error:
          continue

      entities.add(
          result.start(result.lastgroup), result.lastgroup, entity_value) 
开发者ID:pcbje,项目名称:gransk,代码行数:25,代码来源:find_entities.py

示例9: validate_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def validate_ip(ip_address, strict=True):
    """Check if the IPv4 address is valid.

    :param ip_address: IPv4 address value to validate.
    :type ip_address: str
    :param strict: Whether to raise exception if validation fails.
    :type strict: bool
    :raises ValueError: When validation fails and strict is set to True.

    """
    try:
        socket.inet_aton(ip_address)
        return True
    except socket.error:
        error_message = "Invalid IP address: {!r}".format(ip_address)
        LOGGER.warning(error_message, ip_address=ip_address)
        if strict:
            raise ValueError(error_message)
        return False 
开发者ID:GreyNoise-Intelligence,项目名称:pygreynoise,代码行数:21,代码来源:util.py

示例10: parse_ip_literal

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def parse_ip_literal(ast):
    socket.inet_aton(ast.value)

    return ast.value 
开发者ID:apache,项目名称:incubator-spot,代码行数:6,代码来源:common.py

示例11: addr_to_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def addr_to_ip(addr):
    try:
        socket.inet_aton(addr)
        return True
    except socket.error:
        return False 
开发者ID:pkkid,项目名称:pkmeter,代码行数:8,代码来源:utils.py

示例12: craft_arp_packet

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def craft_arp_packet(packet, dst_mac):
    arp_packet = [
        packet["htype"],
        packet["ptype"],
        packet["hlen"],
        packet["plen"],
        struct.pack("!h", 2),
        binascii.unhexlify(dst_mac.replace(':', '')),
        socket.inet_aton(packet["dst_ip"]),
        binascii.unhexlify(packet["src_mac"].replace(':', '')),
        socket.inet_aton(packet["src_ip"])]

    return arp_packet 
开发者ID:sdn-ixp,项目名称:iSDX,代码行数:15,代码来源:utils.py

示例13: craft_garp_response

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def craft_garp_response(SPA, TPA, SHA, THA, eth_src, eth_dst):
    "Craft Gratuitous ARP Response Message"
    """
    Format ARP reply:
    eth_src = VMAC, eth_dst = requester_mac, SHA = VMAC, SPA = vnhip, THA = requester_mac, TPA = requester_ip

    Format gratuitous ARP:
    eth_src = VMAC, eth_dst = 00..00<part_id>, SHA = VMAC, SPA = vnhip, THA = VMAC, TPA = vnhip
    """
    arp_packet = [
        # HTYPE
        struct.pack("!h", 1),
        # PTYPE (IPv4)
        struct.pack("!h", 0x0800),
        # HLEN
        struct.pack("!B", 6),
        # PLEN
        struct.pack("!B", 4),
        # OPER (reply)
        struct.pack("!h", 2),
        # SHA
        binascii.unhexlify(SHA.replace(':', '')),
        # SPA
        socket.inet_aton(str(SPA)),
        # THA
        binascii.unhexlify(THA.replace(':', '')),
        # TPA
        socket.inet_aton(str(TPA))
    ]
    eth_frame = [
        # Destination address:
        binascii.unhexlify(eth_dst.replace(':', '')),
        # Source address:
        binascii.unhexlify(eth_src.replace(':', '')),
        # Protocol
        struct.pack("!h", ETH_TYPE_ARP),
        # Data
        ''.join(arp_packet)
    ]
    return ''.join(eth_frame) 
开发者ID:sdn-ixp,项目名称:iSDX,代码行数:42,代码来源:utils.py

示例14: ip_to_long

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def ip_to_long(ip):
    return struct.unpack('!L', socket.inet_aton(ip))[0] 
开发者ID:sdn-ixp,项目名称:iSDX,代码行数:4,代码来源:decision_process.py

示例15: do_hello

# 需要导入模块: import socket [as 别名]
# 或者: from socket import inet_aton [as 别名]
def do_hello(self):
		# TODO: maybe change this later to push some more info, not only the 
		# private IP
		message = socket.inet_aton(self.config.get("Global", "clientip"))
		self.send(common.CONTROL_CHANNEL_BYTE, common.CONTROL_INIT+message, 
			 (self.server_tuple, 0, None))

	# Polite signal towards the server to tell that the client is leaving
	# Can be spoofed? if there is no encryption. Who cares? 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:11,代码来源:DNS.py


注:本文中的socket.inet_aton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。