HTTP Proxy Checker


/ Published in: Bash
Save to your folder(s)

This script tries to detect whether an HTTP Proxy works or not. It uses the HEAD command (high-level version of the lwp-request command) to connect to a given URL (http://www.google.com by default) via the given HTTP Proxy.
It takes 2 arguments; the first one is the IP Address or URL of the HTTP Proxy and the second one is its port number.
If you have a simpler or faster method, please let me know.


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. # HTTP Proxy Server's IP Address (or URL)
  3. proxy_server=$1
  4.  
  5. # HTTP Proxy Server's Port Number
  6. port=$2
  7.  
  8. # We're trying to reach this url via the given HTTP Proxy Server
  9. # (http://www.google.com by default)
  10. url="http://www.google.com"
  11.  
  12. # Timeout time (in seconds)
  13. timeout=20
  14.  
  15. # We're fetching the return code and assigning it to the $result variable
  16. result=`HEAD -d -p http://$proxy_server:$port -t $timeout $url`
  17.  
  18. # If the return code is 200, we've reached to $url successfully
  19. if [ "$result" = "200 OK" ]; then
  20. echo "1 (proxy works)"
  21. # Otherwise, we've got a problem (either the HTTP Proxy Server does not work
  22. # or the request timed out)
  23. else
  24. echo "0 (proxy does not work or request timed out)"
  25. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.