Tuesday 15 January 2013

python - how to find all ip addresses between 2 ip addresses -


Can someone think of an algorithm that it can keep all the addresses between two other addresses and list them Can you keep using (in dragon)? For example:

  Search IP ('111.111.111.0', '111.111.111.3')   

Back ('111.111.111.0' 111.111.111.1 ',' 111.111.111.2 ',' 111.111.111.3 ') . My main problem occurs when related blocks are the same otherwise I could simply use nested for loop with range function.

with Python 3.3 Standard Library / Python 3.2, with Python 2.x < Try: ip_address def findIPs (start, end) as: start = ip_address (start) end = ip_address (end) result = [] while launching ip_address import ipraddress & Lt; = End: result.append (str (start)) + 1 return result print (search id ('111.111.111.0', '111.111.11.3'))

Python 3.2-, Python 2.x
  import structure import socket DAIP search IP (start, end): ipstruct = struct start ('' gt; I '), = ipstruct.unpack (socket.inet_aton (start) ) End, = ipstruct.unpack (socket.inet_aton (end)) back to socket.inet_ntoa (ipstruct.pack (i)) in category i (start, end + 1)] print (iitip ('111.111.111.0' , '111.111.111.3'))    

No comments:

Post a Comment