메뉴 건너뛰기

Hello :0

[Python] simple ip range

2016.12.19 16:37

Leekyu 조회 수:136

def ipRange(start_ip, end_ip):
   start = list(map(int, start_ip.split(".")))
   end = list(map(int, end_ip.split(".")))
   temp = start
   ip_range = []
   
   ip_range.append(start_ip)
   while temp != end:
      start[3] += 1
      for i in (3, 2, 1):
         if temp[i] == 256:
            temp[i] = 0
            temp[i-1] += 1
      ip_range.append(".".join(map(str, temp)))    
     
   return ip_range
   
   
# sample usage
ip_range = ipRange("192.168.2.0", "192.168.2.10")
print ip_range

http://cmikavac.net/2011/09/11/how-to-generate-an-ip-range-list-in-python/