I've been trying to have an array of ip addresses go through a loop one at a time. Then compare if the current element is in another array of ip addresses. I've traced my error with /bin/bash -x
+ for c in '"${ip[@]}"'
./netk5: line 65: 50.17.231.23 23.64.146.110 23.64.159.139 107.14.36.129 31.13.74.7 173.194.77.95: syntax error: invalid arithmetic operator (error token is ".17.231.23 23.64.146.110 23.64.159.139 107.14.36.129 31.13.74.7 173.194.77.95")
From what I found on Google it seems Bash isn't great at comparing floating point numbers. I saw some suggestions on piping through bc first, but I'm unfamiliar with how that would work here. Perhaps there's also a simpler way.
Here is the code I'm using:
#!/bin/bash -x
fox="firefox"
declare -a white
while true
do
stat=`netstat -antup | awk '{ print $7 }' | grep firefox | sed -ne "s/^[^\/]\+\///p" | awk '!x[$0]++';`
b=$stat
if [ "$b" = "$fox" ];
then
getip=`netstat -antup | grep firefox | awk '{ print $5 }' | sed -e 's/:[^:]*$//' | awk '!x[$0]++';`
ip+=$getip
for c in "${ip[@]}"
do
if [ $c == "${white[$c]}" ]
then
echo -e "${white[$c]} in array\n"
else
echo -e "Not in array"
pass=${ip[$c]}
white+=$pass
# clear array to avoid duplicates
unset ip
fi
done
fi
sleep 2
done
Right now it looks to see if an ip Firefox is connected to is in the "white" array. You may have to refresh your browser to get an ip.
UPDATE: It doesn't seem to be an issue with bc. I tried using the following to get the first ip's and the error persists:
timeout 1 bc | netstat -antup | grep firefox | awk '{ print $5 }' | sed -e 's/:[^:]*$//' | awk '!x[$0]++'