Your challenge is to write a function that accepts starting and ending IPv4 addresses and returns the number of IP addresses from start to end, exc...
For further actions, you may consider blocking this person and/or reporting abuse
Ruby, and totally cheating by using it's IPAddr class :)
This actually made me chuckle... lol cheating indeed 😁
And it was my first idea as well... IPv4 Addresses are 4byte integers... so the easiest way is to subtract them. 😎
ip2int()
is from Stack Overflow.Here's mine! I extended it a little to work if the start and end were reversed.
Gist: gist.github.com/kerrishotts/797450...
Perl, using recursion. Tests included. It throws an exception if the end address precedes the start one.
Here is the simple solution with Python:
Python IPv4 and IPv6:
Elixir:
JavaScript
A bit verbose, but it seems to work fine. Live demo on CodePen.
in C#
PHP :D
demo: 3v4l.org/8NiWc