How can I loop through an IP address range in python

前端 未结 5 1790
一向
一向 2020-12-16 02:55

How can I loop through an IP address range in python? Lets say I want to loop through every IP from 192.168.1.1 to 192.168. How can this be done?

5条回答
  •  别那么骄傲
    2020-12-16 03:31

    You can use itertools.product:

    for i,j in product(range(256),range(256)):
        print "192.168.{0}.{1}".format(i,j)
    

提交回复
热议问题