封面

简单的IP地址计算

刚开始在学习路由交换接触到网络的时候,最头疼的莫过于对IP地址子网掩码的计算,对于数字不敏感的我实在是一时半会算不出来。

最近发现linux的一个软件恰巧可以解决这一个难题。

ipcalc

语法

ipcalc(选项)

选项

-n --nocolor  Don't display ANSI color codes.
 -c --color    Display ANSI color codes (default).
 -b --nobinary Suppress the bitwise output.
 -c --class    Just print bit-count-mask of given address.
 -h --html     Display results as HTML (not finished in this version).
 -v --version  Print Version.
 -s --split n1 n2 n3
               Split into networks of size n1, n2, n3.
 -r --range    Deaggregate address range.
    --help     Longer help text.

实例

ipcalc 192.168.0.1/24

diudiu@miox:~$ ipcalc 192.168.0.1 255.255.255.0
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

ipcalc 192.168.0.1/255.255.128.0

diudiu@mio:~$ ipcalc 192.168.0.1/255.255.128.0
Address:   192.168.0.1          11000000.10101000.0 0000000.00000001
Netmask:   255.255.128.0 = 17   11111111.11111111.1 0000000.00000000
Wildcard:  0.0.127.255          00000000.00000000.0 1111111.11111111
=>
Network:   192.168.0.0/17       11000000.10101000.0 0000000.00000000
HostMin:   192.168.0.1          11000000.10101000.0 0000000.00000001
HostMax:   192.168.127.254      11000000.10101000.0 1111111.11111110
Broadcast: 192.168.127.255      11000000.10101000.0 1111111.11111111
Hosts/Net: 32766                 Class C, Private Internet

ipcalc 192.168.0.1 255.255.128.0 255.255.192.0

diudiu@mio:~$ ipcalc 192.168.0.1 255.255.128.0 255.255.192.0
Address:   192.168.0.1          11000000.10101000.0 0000000.00000001
Netmask:   255.255.128.0 = 17   11111111.11111111.1 0000000.00000000
Wildcard:  0.0.127.255          00000000.00000000.0 1111111.11111111
=>
Network:   192.168.0.0/17       11000000.10101000.0 0000000.00000000
HostMin:   192.168.0.1          11000000.10101000.0 0000000.00000001
HostMax:   192.168.127.254      11000000.10101000.0 1111111.11111110
Broadcast: 192.168.127.255      11000000.10101000.0 1111111.11111111
Hosts/Net: 32766                 Class C, Private Internet

Subnets after transition from /17 to /18

Netmask:   255.255.192.0 = 18   11111111.11111111.11 000000.00000000
Wildcard:  0.0.63.255           00000000.00000000.00 111111.11111111

 1.
Network:   192.168.0.0/18       11000000.10101000.00 000000.00000000
HostMin:   192.168.0.1          11000000.10101000.00 000000.00000001
HostMax:   192.168.63.254       11000000.10101000.00 111111.11111110
Broadcast: 192.168.63.255       11000000.10101000.00 111111.11111111
Hosts/Net: 16382                 Class C, Private Internet

 2.
Network:   192.168.64.0/18      11000000.10101000.01 000000.00000000
HostMin:   192.168.64.1         11000000.10101000.01 000000.00000001
HostMax:   192.168.127.254      11000000.10101000.01 111111.11111110
Broadcast: 192.168.127.255      11000000.10101000.01 111111.11111111
Hosts/Net: 16382                 Class C, Private Internet

Subnets:   2
Hosts:     32764

ipcalc 192.168.0.1 0.0.63.255

diudiu@mio:~$ ipcalc 192.168.0.1 0.0.63.255

WILDCARD
Address:   192.168.0.1          11000000.10101000.00 000000.00000001
Netmask:   255.255.192.0 = 18   11111111.11111111.11 000000.00000000
Wildcard:  0.0.63.255           00000000.00000000.00 111111.11111111
=>
Network:   192.168.0.0/18       11000000.10101000.00 000000.00000000
HostMin:   192.168.0.1          11000000.10101000.00 000000.00000001
HostMax:   192.168.63.254       11000000.10101000.00 111111.11111110
Broadcast: 192.168.63.255       11000000.10101000.00 111111.11111111
Hosts/Net: 16382                 Class C, Private Internet