【问题标题】:ip proxy testing using wget not working使用 wget 的 ip 代理测试不起作用
【发布时间】:2014-06-08 05:00:05
【问题描述】:

我正在通过下载一些东西来测试一些 IP:Port 代理,以查看其中一些代理是否有效。我的工作脚本是

#!/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

wget 成功的典型输出是

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

失败时的输出是

--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.

现在的问题是,grep 似乎不起作用!它在 notok.txt 文件中输出所有 IP 地址。天气 wget 成功与否它输出 notok.txt 中的所有地址。我该如何解决这个问题?

【问题讨论】:

    标签: bash ubuntu proxy grep wget


    【解决方案1】:

    以下是一些更正:

    1) 你应该避免使用for i in $(cmd)。你应该阅读:

    2) grep 必须读取流:

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

    3) 在这种情况下不需要使用grep

    #!/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
    

    【讨论】:

      【解决方案2】:

      使用 wget 检查代理列表的 Bash 脚本

      #!/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"
      

      【讨论】:

        猜你喜欢
        • 2013-10-10
        • 1970-01-01
        • 1970-01-01
        • 2020-10-10
        • 1970-01-01
        • 2015-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多