本文整理匯總了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
示例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
示例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
示例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.
示例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
示例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
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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]
示例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?