Python IPv4 and IPv6:
def ipsBetween(s,e): #Ipv4 if s == e : return 0 s,e,n=s.split('.'),e.split('.'),0 for i in range(len(s)): if s[i] < e[i]: n+=int(e[i]) elif s[i] == e[i] and n>0: n+=255 elif s[i]>e[i]: n+=255-int(s[i]) return n def ipsBetweenIPv6(s,e): #Ipv6 s= [int(i,16) for i in s.split(':')] e= [int(i,16) for i in e.split(':')] return sum(map(int,e))- sum(map(int,s)) print(ipsBetween("10.0.0.0", "10.0.0.50")) print(ipsBetween("10.0.0.0", "10.0.1.0")) print(ipsBetween("20.0.0.10", "20.0.1.0")) print(ipsBetweenIPv6('2001:db8:85a3:8d3:1319:8a2e:370:7348','2001:db8:85a3:8d3:1319:8a2e:3a0:7348')) #48
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python IPv4 and IPv6: