Calculate IP range by subnet mask

前端 未结 4 1590
傲寒
傲寒 2020-12-31 20:12

If I have a subnet mask e.g. 255.255.255.0 and an ip address 192.168.1.5, is there an easy way to determine all the possible ip addresses within th

4条回答
  •  长情又很酷
    2020-12-31 20:25

    To determine the adress range follow these steps :

    1) Take your subnet mask (here 255.255.255.0) and convert it in binary :

    11111111.11111111.11111111.00000000
    
     (  8    +    8   +   8    +    0    = 24 ->  So you can write your ip adresse like this : 192.168.1.x/24 because you are in a /24 network)
    

    2) You have in a /24 network 256-2=254 usable ip adresses for host (one is for the network adress (the first in your range) and the other one is for the broadcast adress (the last in your range)).

    3) To get your range simply get your network adress (the first ip adress according to your subnet mask) and get the next 255 ip addresses and you'll have your range.

    Your network adress:

    In binary the last octet has to be null :

    xxxxxxxx.xxxxxxxx.xxxxxxxx.00000000
    

    Your broadcast adress:

    In binary the last octet has to be equal to 1:

    xxxxxxxx.xxxxxxxx.xxxxxxxx.11111111
    

    Here your ip adress is 192.168.1.5. In binary we get:

    11000000.10101000.00000000.00000101
    
    1. Your network address: 11000000.10101000.00000000.00000000 <-> 192.168.1.0
    2. Your broadcast address: 11000000.10101000.000000000.11111111 <-> 192.168.1.255
    3. First usable ip address: 192.168.1.1

    4. Last usable ip address : 192.168.1.254

    Hope you enjoyed reading bad english. Tell me if you have any question, Loris

提交回复
热议问题