Python generates IP addresses in the correct order based on the quantity
A simple requirement and a simple script.
From an ip address, generate the correct ip address according to the specified quantity.
#! /Usr/bin/env python # encoding: utf-8import osdef getip (ip, count): count = int (count) ip2 = int (ip. split ('. ') [-2]) ip1 = int (ip. split ('. ') [-1]) ip_before =' % s. % s' % (ip. split ('. ') [0], ip. split ('. ') [1]) for I in range (0, count): new_ip1 = ip1 + I if 11 <= new_ip1 <= 254: print' % s. % s. % s' % (ip_before, str (ip2), str (new_ip1) else: new_ip2 = ip2 + int (new_ip1/254) new_ip1 = new_ip1 % 254 + 10 print '% s. % s. % s' % (ip_before, str (new_ip2), str (new_ip1) if _ name _ = '_ main _': getip ('10. 0.1.111 ', 1000)
The algorithm is relatively simple, and the IP addresses of broadcast and 1-10 are retained. In actual use, only the second-to-last position of the ip address is written for future use.