-2

I coded a bash script for an ip sweeper however it keeps giving me ths "name or service not known" output. Here is the code :

Code

And here is the output when I run the script :

Output

Can you please help? I am relitively new to this but eager to learn

1 Answers1

0

This is what I think you want.

I replaced [ "$1" == ] with [ -z "$1" ], and no more errors.

#!/bin/bash
if [ -z "$1" ]
then echo "You forgot an ip address!"
    echo "Syntax ./ipsweep.sh 192.168.1"
else
    for ip in $(seq 1 254)
    do ping -c1 $1.$ip |grep "64 bytes"|cut -d " " -f4 |tr -d ":" |tee -a iplist.txt
done
fi
echo -e "\nComplete. Results can be found in the file iplist.txt"

I swapped out the 2nd ping line and replaced it with the tee command. It will print on the screen and into the iplist.txt file. Not to mention make your script run a lot faster.

tinlyx
  • 678