Calculate IP range by subnet mask

前端 未结 4 1580
傲寒
傲寒 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:26

    yup, convert everything to 32-bit representation (assuming IPv4). if your mask is M and ip is IP, then your ip range is (M&IP)+1,(M&IP)+2,...,(M&IP)+(~M)-1. where & is bitwise AND and ~ is bitwise not.

    to convert things to 32-bit representation, each spot in the ip a.b.c.d is an 8-bit number.

提交回复
热议问题