如果你有nmap
可用你可以运行类似:
nmap -n -sL 72.21.110.0/16
这将沿着线产生输出:
Nmap scan report for 72.21.0.0
Nmap scan report for 72.21.0.1
Nmap scan report for 72.21.0.2
[...]
Nmap scan report for 72.21.255.253
Nmap scan report for 72.21.255.254
Nmap scan report for 72.21.255.255
Nmap done: 65536 IP addresses (0 hosts up) scanned in 33.42 seconds
答案this question建议使用ipcalc
的解决方案。并经发现,我想我这个标记为重复...
更新
在awk
一种解决方案,只为你:
BEGIN {
FS="/"
}
{
split($1, octets, ".");
base=lshift(octets[1], 24) + lshift(octets[2], 16)
+ lshift(octets[3], 8) + octets[4];
max=lshift(1, 32-$2);
for (i=0; i<max; i++) {
addr = base + i;
addr = sprintf("%s.%s.%s.%d", rshift(addr, 24),
rshift(and(addr, 0x00FF0000), 16),
rshift(and(addr, 0x0000FF00), 8),
and(addr, 0xFF))
print addr
}
}
这样给定输入:
$ echo 192.168.1.0/28 | awk -f ipranger.awk
你得到的输出是这样的:
192.168.0.0
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
192.168.0.6
192.168.0.7
192.168.0.8
192.168.0.9
192.168.0.10
192.168.0.11
192.168.0.12
192.168.0.13
192.168.0.14
192.168.0.15
提供的解决方案仅适用于一半的情况,因为并非所有使用脚本或命令的服务器都具有Nmap。无论如何,感谢您的快速响应。 –
我已经添加了一个纯粹的'awk'解决方案。 – larsks