如果你不是很熟悉网络掩码计算,每次要从一个IP和掩码中得到有效的IP地址总是很烦人,要推算好几次。
一个小工具IPgen,可以根据掩码生成有效IP地址。
项目地址:
https://github.com/royhills/ipgen
来自:
Man手册
The IP networks can be specified in the following ways:
a) CIDR notation IPnetwork/bits (e.g. 192.168.1.0/24)
b) Network and mask notation IPnetwork:NetMask (e.g. 192.168.1.0:255.255.255.0)
c) Range notation IPstart-IPend (e.g. 192.168.1.3-192.168.1.27)
d) Single IP Host Address (e.g. 192.168.1.1)
The CIDR and Network:mask notations generate IP host addresses excluding the
network and broadcast addresses. So 10.0.0.0/29 would generate six IP addresses
from 10.0.0.1 to 10.0.0.6 inclusive. But see the description of the --network
(-n) and --broadcast (-b) options below.
The generated IP host addresses are written to standard output, with one IP
address per line.
The IP networks may be specified either on the command line, or read from the
file specified with the --file (-f) option.
Options:
--help or -h Display this usage message and exit.
--file=<f> or -f <f> Read IP networks from the specified file instead of
from the command line. One IP network specification per
line. Use "-" for standard input.
--version or -V Display program version and exit.
--network or -n Include the IP network address.
--broadcast or -b Include the IP broadcast address.
常用命令
我已经有一个地址192.168.10.139,需要新的地址段,扩大到8个地址,要在29位掩码范围内。
ftpuser@hwcgback:~/ipgen$ ipgen 192.168.10.139/29 -b -n
WARNING: host part of 192.168.10.139/29 is non-zero
192.168.10.136
192.168.10.137
192.168.10.138
192.168.10.139
192.168.10.140
192.168.10.141
192.168.10.142
192.168.10.143
还可以用掩码方式
ftpuser@hwcgback:~/ipgen$ ipgen 192.168.10.139:255.255.255.248 -b -n
WARNING: host part of 192.168.10.139:255.255.255.248 is non-zero
192.168.10.136
192.168.10.137
192.168.10.138
192.168.10.139
192.168.10.140
192.168.10.141
192.168.10.142
192.168.10.143