Python randomly generated IP address as string

前端 未结 9 2194
遥遥无期
遥遥无期 2020-12-29 23:14

In Python, what should I do if I want to generate a random string in the form of an IP address?

For example: \"10.0.1.1\", \"10.0.3.14\",

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 23:47

    https://faker.readthedocs.io/en/latest/providers/faker.providers.internet.html

    import faker
    fake = Factory.create()
    ip_addr = fake.ipv4(network=False)
    

    lib has a lot of other useful options to fake data.

提交回复
热议问题