用于测试代理的 Shell 脚本

用于测试代理的 Shell 脚本

我在我的 Linux 服务器上安装了一个 HTTPIE 工具来测试我们的代理对 google.com 等网站的响应,我正在尝试编写一个脚本来测试我们的流量是否通过代理例如:我希望脚本运行下面的命令,如果我得到包括 200 OK 的结果,那么流量就正常,如果我没有得到响应,那么我希望脚本发送一封电子邮件,让我知道该命令没有返回结果。

下面是示例,然后是我编写的脚本的第一部分

# http --proxy=http:http://my_proxy:3128 head www.google.com

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 4622
Content-Type: text/html; charset=ISO-8859-1
Date: Sat, 28 Apr 2018 01:40:13 GMT
Expires: -1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Proxy-Connection: keep-alive
Server: gws
Set-Cookie: 1P_JAR=2018-04-28-01; expires=Mon, 28-May-2018 01:40:13 GMT; path=/; domain=.google.com
Set-Cookie: NID=129=eWFNZlP7mCtJ_zVH7sa6kxTOc9ebMpwLMgUSVnfMA1_bJM2UFfZwly9-BqDSPFI2EaY45t7GhTAte-w783Od3JZ5MGcqmjxT86h8yKdAK1t1qlCm9oexkaYRFgRp64MK; expires=Sun, 28-Oct-2018 01:40:13 GMT; path=/; domain=.google.com; HttpOnly
Via: 1.1 isdsecwsandc2.tch.harvard.edu:3128 (Cisco-WSA/10.5.2-042)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block

所以我只想编写一个脚本来针对每个代理 IP 地址运行上面的命令,如果我得到 200 OK 返回,则转到下一个,如果超时,则给我发送一封电子邮件让我知道

脚本在这里:

#!/bin/bash

proxy_targets="http://10.5.5.5:3128  http://10.5.5.6:3128 http://10.5.5.7:3128"

failed_hosts=""

for i in $proxy_targets
do
        http --proxy=http:$i head www.google.com > /dev/null

相关内容