當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。