Linux script that scans the network

i have a question i want to run a script that scans my network and that i can see with devices are up in my network. I want to paste some arguments also in the script

When i run the script: ./ping.sh –xx-YY 20 50

Output:

192.168.0.20 is down 

192.168.0.21 is up 

…………………………….

192.168.0.50 is up

the argument -t , counts 200 by the last digit for ex.
./ping.sh -t 20
output: 192.168.0.220 is up

But my problem is de argument –up en -mac
I want when i run the script ./ping.sh –up , its only display the computers there are up

And the argument – mac is also a problem when I run the script i want to display the ip addresses and de mac address after the computers are ping

This is my script.

#!/bin/bash

while [[ -n "$@" ]]
do
    case "$1" in

    -h|--help)
    Extension=1
    shift
    ;;

    -XX-YY)
    Extension=2
    shift
    min=$1
    shift
    max=$1
    shift

    ;;

    --up)
    Extension=3
    shift
    end=$1
    shift
    ;;

    -t)
    Extension=4
    shift
    count=$(($1+200))
    shift
    ;;
    esac
done

if [ "$Extension" -eq 1 ] ; then

    echo "dit is de help"

fi


if [ "$Extension" -eq 2 ] ; then

for ((n=$min ; n<=$max ; n+=1))
do
ip=192.168.0.$n
if ping -c 1 -w 1 ${ip} > /dev/null 2> /dev/null >> logping.txt; then
echo "${ip} is up"
else
echo "${ip} is down"
fi
done


fi

if [ "$Extension" -eq 3 ] ; then


                ip=192.168.0.$end
                if ping -c 1 -w 1 ${ip} > /dev/null 2> /dev/null >> /logping.txt; then
                        echo "${ip} is up"

                fi

fi

if [ "$Extension" -eq 4 ] ; then

ip=192.168.0.$count
if ping -c 1 -t 1 ${ip} > /dev/null 2> /dev/null >> logping.txt; then
echo "${ip} is up"
else
echo "${ip} is down"
fi
fi


Source: linux

Leave a Reply