nslookup-scan of IP-range/subnet

Posted by & filed under Linux, Network, Scripting.

#!/bin/bash
# nslookup-scan of IP-range

# It's possible to add more networks separated with space
NETS="192.168.0"

IPRange="1 254"
for NET in $NETS; do
  for n in $(seq $IPRange); do
        ADDR=${NET}.${n}
        echo "${ADDR},`nslookup ${ADDR} | awk -F "=" '{ print $2 }'|sed 's/^[ t]*//' | sed '/^$/d' | |sed 's/.$//'`"
  done
done

Result

192.168.0.1,cba.infra.no
192.168.0.2,bca.infra.no
192.168.0.3,abc.infra.no
192.168.0.4,
192.168.0.5,
192.168.0.6,
192.168.0.7,
192.168.0.8,

One Response to “nslookup-scan of IP-range/subnet”

  1. Zerahl

    #!/bin/bash
    # nsscan.sh
    # nslookup-scan of IP-range

    # Get subnets from arguments
    NETS=$@

    # Handle lack of arguments
    if [ "x$NETS" = "x" ]; then
    echo “Usage example: sh nsscan.sh 192.168.1″
    echo “This would scan 192.168.1.0/24″
    echo “Accepts class C subnets only”
    exit 2
    fi

    IPRange=”1 254″
    for NET in $NETS; do
    for n in $(seq $IPRange); do
    ADDR=${NET}.${n}
    # Only print line if nslookup returns a result
    if [ "x$(nslookup ${ADDR} | awk -F '=' '{ print $2 }'| sed 's/^[ t]*//’ | sed ‘/^$/d’ | sed ‘s/.$//’)” != “x” ]; then
    echo “${ADDR} `nslookup ${ADDR} | awk -F “=” ‘{ print $2 }’|sed ‘s/^[ t]*//’ | sed ‘/^$/d’ | sed ‘s/.$//’`”
    fi
    done
    done

    Reply

Leave a Reply