Bash script to list all IPs in prefix

后端 未结 11 1619
[愿得一人]
[愿得一人] 2020-12-23 12:23

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).

An ex

11条回答
  •  再見小時候
    2020-12-23 13:20

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

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

    From the nmap man page, the flags are:

    -sL: List Scan - simply list targets to scan
    -n: Never do DNS resolution
    

    Just that simple

    The above command outputs this

    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
    

提交回复
热议问题