Please let me have this clear, dont comment or post negatively if you're not willing to help. I have this pure bash script that finds out all IPs on the computer/laptop/server and saves the IPs in an array, also it saves a list of those IPs in a file in the /tmp/ folder for temporary use.
what i'm trying to do is:
a user runs the shell, it'll prompt him/her to enter the public (real) IP address used for internet connection, then it verifies this IP by pinging it to check if its reachable. then if its reachable the script continues and if its not it'll re-ask him/her to enter his/her real (public) IP again.
now i know that pinging any IP from the list will be reachable and the script will run no matter whether he/she entered any of the listed IPs, and i'm working on how to ping it from outside the network to check if its reachable or not. but my question is how can i achieve that? ---> how can i compare the array to the user's input?
here's my script thats getting stuck at the "Please Type Your Public......" question no matter what IP i entered from the list, i know its because of the while or a missing "break".
#!/bin/bash
##--------------START Temp Variables-------------##
KEY_USER="${KEY_USER:-$(whoami)}"
ifconfig | grep Bcast > /tmp/ip1
cat /tmp/ip1 | awk '{ print $2 }' > /tmp/ip2
rm /tmp/ip1
sed -i 's/addr://' /tmp/ip2
#ips=$(cat /tmp/ip2)
howmanyips=$(grep -c "." /tmp/ip2)
for (( i=$howmanyips; i>0; i-- ))
do
head -$i /tmp/ip2|tail -1 > /tmp/$i
done
ipcheck=0
intip=0
##---------------END Temp Variables--------------##
##---------------START Main Script---------------##
code...
code...
code...
code...
##---------------START Prompt Loop---------------##
while true; do
echo -e "\e[33;44m***** CHOOSE YOUR VALID PUBLIC IP *****\e[0m"
cat /tmp/ip2
read -p "Please Type Your Public IP (that has internet access) from above:" uip
readarray -t ips < <(exec ifconfig | awk '/Bcast/ { gsub(/addr:/, "", $2); print $2 }')
for ip in "${ips[@]}"; do
if [ $uip == $ip ]; then
ipcheck=$ip
intip=$i
ping -c 1 $ip > /tmp/ipnetcheck
ipnetcheck=$(grep -ic "0%" /tmp/ipnetcheck)
if [ $ipnetcheck = 1 ]; then
break
else
exit 130
fi
else
break
fi
done
done
thats it, i would really appreciate anyone's help, and thanks in-forward.
Aucun commentaire:
Enregistrer un commentaire