当前位置:   article > 正文

Mac/Linux Curl代理访问测试网站方法

mac 终端测试访问一个网站的链接

HTTP协议测试访问

curl -I  -x 140.205.32.8:80 "http://www.aliyun.com" 

Jietu20171216_221446

HTTPS协议测试访问

curl -I  -s  -k 'https://140.205.32.8/' -H 'Host:www.aliyun.com'

Jietu20171216_221418

解释说明

使用过程中,调整期望的IP以及域名。比如:其他测试通过代理访问http://blog.csdn.net/ 那命令如下:

curl -I  -x x.x.x.x:80 "http://blog.csdn.net" 

对应的IP,调整为对应的代理服务器的IP。

扩展使用

  1. #循环100次使用代理访问https://www.aliyun.com/,返回Response Headers
  2. for i in {1..100};do curl -I -s -k 'https://140.205.32.8/' -H 'Host:www.aliyun.com'; done
  3. #通过代理服务器访问,查看网站内容
  4. curl -s -k 'https://140.205.32.8/' -H 'Host:www.aliyun.com'

相关CURL参数说明

  1. -s/--silent #静音模式。不输出任何东西
  2. -I/--head #只显示文档信息
  3. -k/--insecure #允许不使用证书到SSL站点
  4. -x/--proxy <host[:port]> #在给定的端口上使用HTTP代理

综上编写了一个简单的脚本:
准备工作:

  1. cat ~/.bash_profile
  2. alias web_Proxy='bash /root/Proxy/Proxy.sh'

脚本内容

  1. #!/bin/bash
  2. http(){
  3. curl -I -x $2 "http://"$1
  4. }
  5. https(){
  6. curl -I -k 'https://'$2 -H 'Host:'$1
  7. }
  8. if [[ $1 == 'http' ]];then
  9. if [[ ! -n $4 ]];then
  10. http $2 $3
  11. else
  12. for ((i=0;i<$4;i++))
  13. do
  14. date;
  15. http $2 $3;
  16. done
  17. fi
  18. elif [[ $1 == 'https' ]]; then
  19. # https $2 $3
  20. if [[ ! -n $4 ]];then
  21. https $2 $3
  22. else
  23. for ((i=0;i<$4;i++))
  24. do
  25. date;
  26. https $2 $3;
  27. done
  28. fi
  29. else
  30. echo -e 'Usage: \nweb_Proxy http www.baidu.com 8.8.8.8:80 10 \nweb_Proxy 协议 域名 地址:端口 循环访问次数'
  31. fi

使用示例:

  1. Mac-Pro:~ Test$ web_Proxy http www.aliyun.com 140.205.172.20:80 2
  2. 2018219日 星期一 000720秒 CST
  3. HTTP/1.1 301 Moved Permanently
  4. Date: Sun, 18 Feb 2018 16:07:20 GMT
  5. Content-Type: text/html
  6. Content-Length: 286
  7. Connection: keep-alive
  8. Location: https://www.aliyun.com/
  9. Server: Tengine/Aserver
  10. EagleEye-TraceId: 0b83df9215189700406686721e7a8c
  11. Timing-Allow-Origin: *
  12. 2018219日 星期一 000720秒 CST
  13. HTTP/1.1 301 Moved Permanently
  14. Date: Sun, 18 Feb 2018 16:07:20 GMT
  15. Content-Type: text/html
  16. Content-Length: 286
  17. Connection: keep-alive
  18. Location: https://www.aliyun.com/
  19. Server: Tengine/Aserver
  20. EagleEye-TraceId: 0b83a4e715189700407331684e84d1
  21. Timing-Allow-Origin: *

更多内容见Man Curl

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/336147
推荐阅读
相关标签
  

闽ICP备14008679号