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