本文整理匯總了Python中ipaddress.IPAddress方法的典型用法代碼示例。如果您正苦於以下問題:Python ipaddress.IPAddress方法的具體用法?Python ipaddress.IPAddress怎麽用?Python ipaddress.IPAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ipaddress
的用法示例。
在下文中一共展示了ipaddress.IPAddress方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_ip
# 需要導入模塊: import ipaddress [as 別名]
# 或者: from ipaddress import IPAddress [as 別名]
def set_ip(self, i):
"Set connect ip, and ip6 or ip4 mode."
self.iplist = False
if i.lower() == 'list':
self.iplist = []
ip6 = False
elif i.lower() == 'list6':
self.iplist = []
ip6 = True
else:
try:
self.ipaddr = ipaddress.ip_address(i)
except AttributeError:
self.ipaddr = ipaddress.IPAddress(i)
if self.ipaddr.version == 6:
if self.ipaddr.ipv4_mapped:
self.ipaddr = ipaddress.IPv4Address(self.ipaddr.ipv4_mapped)
ip6 = False
else:
ip6 = True
else:
ip6 = False
self.c = str(self.ipaddr)
# NOTE: self.A is not lowercase, so isn't a macro. See query.expand()
if ip6:
self.A = 'AAAA'
self.v = 'ip6'
self.i = '.'.join(list(self.ipaddr.exploded.replace(':','').upper()))
self.cidrmax = 128
else:
self.A = 'A'
self.v = 'in-addr'
self.i = self.ipaddr.exploded
self.cidrmax = 32