Proxy socks tester issue

I have a list of ip socks / port(eg: 192.168.0.1 80). I would like to write a bash to test automatically these addresses in a loop with firefox. The problem is that firefox process stays alive even when firefox does not work because of wrong network settings. So I want to kill the process when the browser does not work. I was thinking of the condition:

timeout 10s watch -n 1 'netstat -a | grep "ESTA http"'

If such command return true, break and exit, otherwise kill firefox and continue.
I dont know how to traduce an output command in a boolean condition. If (output commnand) or if !(output command)
Here is what my script looks like:

#1. read the list

sort -R list | while read -r IP PORT           
do

#2.clean firefox user preference

grep -v "network.proxy.\(socks\|socks_port\|type\)" prefs.js  > temp && mv temp prefs.js

#3. set user preference with the current ip/port in the list

cat <<EOT >> prefs.js
user_pref("network.proxy.socks", "$IP");
user_pref("network.proxy.socks_port", $PORT);
user_pref("network.proxy.type", 1);
EOT

#4.launch firefox

firefox;

#5 is it working?

timeout 10s watch -n 1 'netstat -a | grep "ESTA http"'&; 

#6 from there I don't how to traduce in bash the following:

if (output of #5) 
    break;

if !(output of #5) kill $(ps aux | grep 'firefox' | awk '{print $2}')

done;

exit;

thanx guys !

---------- Post updated at 11:24 AM ---------- Previous update was at 08:22 AM ----------

actually, there should be IFS=' '; before the while loop.
I have improved a little bit; the only thing is that it does not break where I want it to break:

#!/bin/bash

IFS=' ';
sort -R sokslist | while read -r IP PORT           
do

grep -v "network.proxy.\(socks\|socks_port\|type\)" prefs.js  > temp && mv temp prefs.js

cat <<EOT >> prefs.js
user_pref("network.proxy.socks", "$IP");
user_pref("network.proxy.socks_port", $PORT);
user_pref("network.proxy.type", 1);
EOT

firefox;

timeout 10s watch -n 1 'netstat -a | grep "http    ESTA"' |  break; 

#it should break there, but it does not 


kill $(ps aux | grep 'firefox' | awk '{print $2}');

done;

exit

firefox is a way over-complex program for a simple IP/port testing tool.

Can't you just use nc -z like this:

sort -R list | while read -r IP PORT
do
   if nc -z $IP $PORT
   then
       echo "$IP:$PORT tested OK"
   else
       echo "$IP:$PORT FAILED"
   fi
done

or, as you appear to be using the bash shell, you could use the bash built-in /dev/tcp

sort -R list | while read -r IP PORT
do
   if 2>/dev/null >/dev/tcp/$IP/$PORT
   then
       echo "$IP:$PORT tested OK"
   else
       echo "$IP:$PORT FAILED"
   fi
done

Don't use a pipe before the break, but either && or || , depending on which condition you need.

Eh, thanx a bunch for your posts guys indeed !
Chubler, my list was built with nc (sometimes, connection is ok with nc but not with firefox)
My script is running now (I sent the post from a proxy ;-D):

IFS=' ';
sort -R sokslist | while read -r IP PORT           
do

grep -v "network.proxy.\(socks\|socks_port\|type\)" prefs.js  > temp && mv temp prefs.js

cat <<EOT >> prefs.js
user_pref("network.proxy.socks", "$IP");
user_pref("network.proxy.socks_port", $PORT);
user_pref("network.proxy.type", 1);
EOT

firefox &timeout 10s netstat -a | grep -q ESTA 

if [ $? -eq 0 ] 
    then break 
fi

pkill firefox;

done;

exit;

I think I will let netstat running a longer time to catch an ESTABLISHED.