Bash脚本列出前缀中的所有IP [英] Bash script to list all IPs in prefix

查看:59
本文介绍了Bash脚本列出前缀中的所有IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建可以输入一组前缀的脚本,然后该脚本将列出前缀内的所有IP地址(包括网络/主机/广播).

I'm trying to create script that I can input a set of prefixes, which will then list all IP addresses within the prefixes (including network/host/broadcast).

一个例子是:

./convert-prefix-to-IPs.sh 192.168.0.0/23 203.20.0.0/16
192.168.0.0
192.168.0.1
... 
192.168.0.255
192.168.1.0
.. 
192.168.1.255
203.20.0.0
..
203.20.255.255


有一些python/perl脚本可以做到这一点,但是我希望有一个简单的bash脚本,因为它可以在没有perl/python的系统上使用(是的.我知道..)


There are some python/perl scripts which can do this, but I'm hoping to have a simple bash script, as it may be used on systems without perl/python (yes.. i know.. )

推荐答案

在这里,我用它来生成给定CIDR块中的所有IP地址

Here is what I use to generate all the IP addresses in a given CIDR block

nmap -sL 10.10.64.0/27 | awk '/Nmap scan report/{print $NF}'

就这么简单

上面的命令输出

10.10.64.0
10.10.64.1
10.10.64.2
10.10.64.3
10.10.64.4
10.10.64.5
10.10.64.6
10.10.64.7
10.10.64.8
10.10.64.9
10.10.64.10
10.10.64.11
10.10.64.12
10.10.64.13
10.10.64.14
10.10.64.15
10.10.64.16
10.10.64.17
10.10.64.18
10.10.64.19
10.10.64.20
10.10.64.21
10.10.64.22
10.10.64.23
10.10.64.24
10.10.64.25
10.10.64.26
10.10.64.27
10.10.64.28
10.10.64.29
10.10.64.30
10.10.64.31

这篇关于Bash脚本列出前缀中的所有IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆