借助Python的fake库的internet包
>>> from faker import Faker
>>> from faker.providers import internet
>>> fake=Faker()
带掩码长度
>>> fake.ipv4(network=True)
'192.53.63.160/28'
不带掩码长度
>>> fake.ipv4(network=False)
'4.129.77.8'
还可以生成私网地址、公网地址、某个类型的地址,例如
>>> fake.ipv4(network=True, address_class='a', private=None)
'100.192.0.0/12'
>>> fake.ipv4(network=True, address_class='b', private=None)
'172.0.0.0/6'
>>> fake.ipv4(network=True, address_class='c', private=None)
'203.0.51.128/27'
带掩码长度
>>> fake.ipv6(network=True)
'ced5:5cba:9206::/48'
不带掩码长度
>>> fake.ipv6(network=True)
'aba8:f04:e12c:e0aa:b967:f4bf:481c:d400/119'
>>> fake.mac_address()
u'71:92:6a:b2:4f:b2'
>>> fake.mac_address()
u'ab:1a:ff:1c:cc:6a'
参考链接 https://pypi.org/project/Faker/
https://faker.readthedocs.io/en/stable/providers/faker.providers.internet.html