Stealing Water and Netmasks
I was going for a jog a few weeks ago, late at night, and I noticed that one of my neighbors was watering his lawn - but the hose was plugged into the as-of-yet-unsold house next door. Seriously cheap. I thought it would be fun to get ahold of some of the Traton Homes stationary, and just write "We know." and stick it to his door. This afternoon, I was going for a walk, and he was again doing the exact same thing. That's just ... weird. Whatever.
So, let's say you have an IP address, t, 192.168.1.123 and you are on a subnet with a default gateway, r, 192.168.1.100 with a netmask (also called a subnet mask) of, m, 255.255.255.192 (also expressable as 192.168.1.100/26) and you need to determine whether the IP address falls within the subnet. In short, this can be determined by verifying that the following is true:(r & m) = (t & m)
To see this, lets first look at the binary representation of these three values:192.168.001.123 = 11000000 10101000 00000001 01111011
192.168.001.100 = 11000000 10101000 00000001 01100100
255.255.255.192 = 11111111 11111111 11111111 11000000
The first three octets of the netmask are each 255, signifying that an "exact match" is necessary for those three octets, so lets just skip them and look at the fourth octet:123 = 01111011 (t)100 = 01100100 (r)192 = 11000000 (m)
Now, relating this back to the equation (r & m) = (t & m),01100100 & 11000000 = 01000000 (r & m)01111011 & 11000000 = 01000000 (t & m)
So, now you know. Or, in the case of most of my readers, you don't know, but now you've read it.