D
D
Denis Sechin2017-01-05 19:41:46
Computer networks
Denis Sechin, 2017-01-05 19:41:46

How to check if an ip address belongs to a specific subnet?

Greetings, I didn’t find a clear explanation on the network on how to determine whether the IP address belongs to a specific subnet, how to find the network address, broadcast or match the logical "AND" IP and the mask, I know! Here is an example: which subnet belongs to ipi 10.120.100.255/18 address options
1) 10.120.0.100
2) 10.0.0.0
3) 10.120.64.0
4) 10.120.96.0
PS I do not need a solution, I need the correct calculation algorithm.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Moseychuk, 2017-01-05
@tamogavk

10.120.100.255/18
First represent the address and mask in binary form
00001010.01111000.01100100.11111111/11111111.11111111.11000000.00000000
Then bitwise AND the mask and address.
00001010.01111000.01000000.00000000
Then convert back to decimal.
10.120.64.0

L
lega, 2017-01-05
@lega

You check the left side of the bits and that's it.
And the physical one and the same IP can be on different continents, different subnets (a popular example is 127.0.0.1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question