寫網路程式時,常常要處理和ip address有關的issue。這時候,遇到255.255.255.255 = 32的Mask還好,但是如果是IP address/31 或是 IP address/30呢?
還好,我找到了一個很好用的程式: ipcalc
ipcalc 192.168.0.1/24
下頭是輸出
Address: 192.168.0.1 11000000.10101000.00000000. 00000001
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111
=>
Network: 192.168.0.0/24 11000000.10101000.00000000. 00000000
HostMin: 192.168.0.1 11000000.10101000.00000000. 00000001
HostMax: 192.168.0.254 11000000.10101000.00000000. 11111110
Broadcast: 192.168.0.255 11000000.10101000.00000000. 11111111
Hosts/Net: 254 Class C, Private Internet