Proxy socks tester issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Proxy socks tester issue
# 1  
Old 07-24-2014
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:
Code:
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
Code:
sort -R list | while read -r IP PORT           
do

#2.clean firefox user preference
Code:
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
Code:
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
Code:
firefox;

#5 is it working?
Code:
timeout 10s watch -n 1 'netstat -a | grep "ESTA http"'&;

#6 from there I don't how to traduce in bash the following:
Code:
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:
Code:
#!/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


Last edited by rbatte1; 07-24-2014 at 09:43 AM.. Reason: Converted ICODE tags to CODE tags
# 2  
Old 07-24-2014
firefox is a way over-complex program for a simple IP/port testing tool.

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

Code:
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

Code:
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


Last edited by Chubler_XL; 07-24-2014 at 08:48 PM..
# 3  
Old 07-25-2014
Quote:
Originally Posted by arpagon
. . .
timeout 10s watch -n 1 'netstat -a | grep "http ESTA"' | break;

#it should break there, but it does not

[/CODE]
Don't use a pipe before the break, but either && or || , depending on which condition you need.
# 4  
Old 07-25-2014
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):
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Issue setup Transparent proxy and Gateway using Squid on CentOS 7

Hello, We are migrating our gateways from CentOS 6 to CentOS 7 and for setting up a transparent proxy using squid and Firewalld i am using below configuration. #Firewalld configurations firewall-cmd --permanent --zone=public --add-forward-port=port=80:proto=tcp:toport=3128:toaddr=LAN_IP... (4 Replies)
Discussion started by: sunnysthakur
4 Replies

2. UNIX for Advanced & Expert Users

SOCKS proxy & PAM configuration exposure

I've got a problem with a proxy configuration. We have an LDAP group that lists all users who are authorised to use the proxy to FTP (usually Filezilla) out to the world, and by implication those not in the group should be denied. My users are delighted that this has been enabled and those that... (9 Replies)
Discussion started by: rbatte1
9 Replies

3. Shell Programming and Scripting

Simple proxy tester

This is a simple script to verify a proxy type8code0@core:~$ cat proxy-tester echo -e "\nTest proxy 10.10.10.10:80" curl echoip.net --proxy 10.10.10.10:80 echo -e "\n\nTest proxy 10.10.10.11:80" curl echoip.net --proxy 10.10.10.11:80 echo -e "\n\nTest proxy 10.10.10.13:80" curl echoip.net... (3 Replies)
Discussion started by: type8code0
3 Replies

4. UNIX for Dummies Questions & Answers

Can't connect through ssh socks proxy to certain sites

Hello, i setup an open socks proxy on my remote vps: ssh -f -N -D 0.0.0.0:1080 localhost and then allowed only connections from IP of my home computer iptables -A INPUT --src myhomeip -p tcp --dport 1080 -j ACCEPT iptables -A INPUT -p tcp --dport 1080 -j REJECT but it appears that im... (3 Replies)
Discussion started by: postcd
3 Replies

5. Red Hat

Configuration Reverse Proxy - https issue

Hi All I need your valuable help on this. Im trying to setup reverse proxy using apache in rhel 5.5. I just started with Apache, and not much idea about going with advance level config, except that i have tried to set up this reverse proxy based on an online guide i found in internet. The... (0 Replies)
Discussion started by: niyas_gk
0 Replies

6. Shell Programming and Scripting

Wget vs Curl - Proxy issue

Hi, My script needs to crawl the data from a third party site. Currently it is written in wget. The third party site is of shared interface with different IP addresses. My wget works with all the IP address but not with one. Whereas the curl is able to hit that IP address and comes out... (2 Replies)
Discussion started by: sathyaonnuix
2 Replies

7. IP Networking

How i can setup socks 5 in CentOS?

how i can setup socks 5 in centos? (1 Reply)
Discussion started by: hesamii
1 Replies

8. Linux

How i can setup socks 5 in CentOS?

how i can setup socks 5 in centos? (0 Replies)
Discussion started by: hesamii
0 Replies

9. Shell Programming and Scripting

Bash Login tester Script help!

Hello, first of all, I am a pretty experience c++ programmer, but have never really bothered learning bash scripting at all, so I know conceptually things that can be done in c++, but I'm not too sure about bash. I'm trying to learn Bash, and wanted to start out with a practical application. So I... (1 Reply)
Discussion started by: RSPdev
1 Replies

10. Programming

Issue Related to Proxy Server

Hi All, I am establishing the proxy server to communicate the date between devices using serial port but after serial port connection,it should start the Proxy Server and still run till the communication is happening...but server became started but it became halted due to error - Please... (1 Reply)
Discussion started by: smartgupta
1 Replies
Login or Register to Ask a Question