ipv4地址从最后一位按步长递增
指定要变化的起始ip地址
指定变化步长
指定变化个数
#!/usr/bin/python def ipv4_to_int(ipv4): ipv4 = [int(x) for x in ipv4.split(".")] ipv4_int = (ipv4[0] << 24) + (ipv4[1] << 16) + (ipv4[2] << 8) + ipv4[3] #print(bin(ipv4_int)) return ipv4_int def int_to_ipv4(ip_int): ipv4 = [] for x in (24, 16, 8 ,0): ipv4.append(str(ip_int >> x & 0xFF)) # 这边是关键,和0xFF(11111111)进行于运算,实现进位功能。 #print(ipv4) return ".".join(ipv4) start_ip = "125.164.163.29" for x in range(0,19999): #print(x) ip_address = ipv4_to_int(start_ip) + x * 4 #4为固定步长 #print(ip_address) ip_address = int_to_ipv4(ip_address) print(ip_address) #print("interface gigaEthernet0/1/%d" %x) #print(" ip address %s 255.255.255.252" %ip_address) #print(" no shutdown")