Verifying if two hosts are on the same IPv4 network
Posted by jpluimers on 2011/02/17
Recently, I wrote a bunch of code both in C# and Delphi to verify if two hosts are on the same IPv4 network.
Even though the public IPv4 address space is exhausted (IANA recently allocated the final two IPv4 blocks of their primary pool to APNIC, then allocated the five remaning /8 IPv4 blocks to the RIRs, thereby depleting the IPv4 pool), they are still used a lot, especially in private networks.
Over the next couple of weeks, you will see a couple of blog posts explaining:
- how to get the IPv4 addresses and network masks of network interfaces in your computer
- how to convert those to and from strings
- how to convert a host-name to a list of IP addresses
- how to lookup the current host-name
- how network masks are related to counting leading/trailing ones and zeros
- how to compare two IPv4 addresses given they have the same network masks
Those blog posts will have sample code in both Delphi and C#. And there will be unit tests to verify the underlying code.
–jeroen






KM said
Look here to be aware how IANA wastes IP ranges and spammers take advantage of it…
http://www.spamhaus.org/drop/
jpluimers said
Even when they would get those blocks back, it would only be a matter of time for the problem to reappear.
BTW: The blocks themselves are at http://www.spamhaus.org/drop/drop.lasso
–jeroen