0

I am testing some IP:Port proxy by downloading something to see if some of these proxy valid or not. My working script is

#!/bin/bash

for pro in $(cat testing.txt);do

wget -e use_proxy=yes -e http_proxy=$pro --tries=1 --timeout=15 http://something.com/download.zip
if grep --quiet "200 OK"; then
  echo $pro >> ok.txt
else
  echo $pro >>notok.txt
fi

done

Typical output on success by wget is

--2014-06-08 10:45:31--  http://something.com/download.zip
Connecting to 186.215.168.66:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 30688 (30K) [application/zip]
Saving to: `download.zip'

100%[======================================>] 30,688      7.13K/s   in 4.2s

and output on failure is

--2014-06-08 10:45:44--  http://something.com/download.zip
Connecting to 200.68.9.92:8080... connected.
Proxy request sent, awaiting response... Read error (Connection timed out) in headers.
Giving up.

now problem is , grep seems not working! It output all ip address in notok.txt file. Weather wget success or not it output all address in notok.txt . How can I solve this?

Ibrahim
  • 100
  • 1
  • 9

2 Answers2

0

Here are some corrections :

1) You should avoid to use for i in $(cmd). You should read :

2) grep must read a stream :

grep [options...] [pattern] file
command|grep [options...] [pattern]
grep [options...] [pattern] < <(command)
grep [options...] [pattern] <<< "some text"

3) No need to use grep in this case :

#!/bin/bash

while read -r pro; do
    out="$(wget -e use_proxy=yes -e http_proxy=$pro --tries=1 --timeout=15 http://something.com/download.zip)"
    if [[ $out =~ "200 OK" ]]; then
        echo "$pro" >> ok.txt
    else
        echo "$pro" >> notok.txt
    fi
done < testing.txt
Community
  • 1
  • 1
Idriss Neumann
  • 3,760
  • 2
  • 23
  • 32
0

Bash script to check a list of proxies using wget

#!/usr/bin/bash

files="proxies_list.txt" #file with proxies to test in <ip>:<port> format

rm not_ok.txt
rm ok.txt

while read -r pro; do

    out=$(wget.exe -qO- --tries=1 --timeout=5 --no-check-certificate -e use_proxy=on -e https_proxy=$pro https://example.com)

    if [[ $out ]]; then
        echo "$pro" >> ok.txt
        echo "$pro  ----    OK"
    else
        echo "$pro" >> not_ok.txt
        echo "$pro  ----    NOT OK"
    fi
done < "$files"
gremur
  • 1,645
  • 2
  • 7
  • 20