Human readable DhcpInfo.ipAddress?

后端 未结 5 2142
臣服心动
臣服心动 2021-02-15 10:31

I am wondering how to get a human readable IP Adress from DhcpInfo.ipAddress? The tricky thing about it is, that it is an integer and obviously you can\'t store an IP address in

5条回答
  •  梦如初夏
    2021-02-15 11:20

    obviously you can't store an IP address in an integer

    Actually, that's all an IP (v4) address is -- a 32-bit integer (or 128-bit, in the case of IPv6).

    The "human-readable" format you're talking about is produced by dividing the bits of the integer into groups of 8 called "octets" and converting to base 10, e.g. "192.168.0.1".

    The bits of this address would be as follows (spaces added for readability):

    11000000 10101000 00000000 00000001
    

    Which corresponds to the decimal integer 3,232,235,521.

提交回复
热议问题