本文整理汇总了Python中faker.providers.misc.Provider.ipv4_public方法的典型用法代码示例。如果您正苦于以下问题:Python Provider.ipv4_public方法的具体用法?Python Provider.ipv4_public怎么用?Python Provider.ipv4_public使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类faker.providers.misc.Provider
的用法示例。
在下文中一共展示了Provider.ipv4_public方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ipv4_public
# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import ipv4_public [as 别名]
def test_ipv4_public(self):
from faker.providers.internet import Provider
provider = Provider(self.generator)
for _ in range(99):
address = provider.ipv4_public()
address = six.text_type(address)
assert len(address) >= 7
assert len(address) <= 15
assert not ip_address(address).is_private, address
assert (
re.compile(r'^(\d{1,3}\.){3}\d{1,3}$').search(address))
for _ in range(99):
address = provider.ipv4_public(network=True)
address = six.text_type(address)
assert len(address) >= 9
assert len(address) <= 18
# Hack around ipaddress module
# As 192.0.0.0 is net addr of many 192.0.0.0/* nets
# ipaddress considers them as private
if ip_network(address).network_address != ip_address('192.0.0.0'):
assert not ip_network(address)[0].is_private, address
assert (
re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$').search(address))
示例2: test_ipv4_public_class_c
# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import ipv4_public [as 别名]
def test_ipv4_public_class_c(self):
from faker.providers.internet import Provider
provider = Provider(self.generator)
for _ in range(99):
address = provider.ipv4_public(address_class='c')
address = six.text_type(address)
assert len(address) >= 7
assert len(address) <= 15
assert not ip_address(address).is_private, address