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 :
And here is the output when I run the script :
Can you please help? I am relitively new to this but eager to learn
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 :
And here is the output when I run the script :
Can you please help? I am relitively new to this but eager to learn
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.
seq 1 254
is functionally the same as $(seq 1 254). Though $(seq 1 254) is the newer method.
– Cyberninja
Oct 04 '23 at 15:47
[
- see for example Why are bash tests so picky about whitespace?. – steeldriver Oct 01 '23 at 23:46[10.0.2]
". Do./pingsweep.sh 10.0.2
instead. Also, readman ping
and dosudo ping -c 1 -b 10.0.2.255
to do it all at once. – waltinator Oct 02 '23 at 04:54