如果你有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