proxy_check.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Command line script to check for an open proxy at a specified location
  4. */
  5. if( php_sapi_name() != 'cli' ) {
  6. die( 1 );
  7. }
  8. /**
  9. *
  10. */
  11. $output = '';
  12. /**
  13. * Exit if there are not enough parameters, or if it's not command line mode
  14. */
  15. if ( ( isset( $_REQUEST ) && array_key_exists( 'argv', $_REQUEST ) ) || count( $argv ) < 4 ) {
  16. $output .= "Incorrect parameters\n";
  17. } else {
  18. /**
  19. * Get parameters
  20. */
  21. $ip = $argv[1];
  22. $port = $argv[2];
  23. $url = $argv[3];
  24. $host = trim(`hostname`);
  25. $output = "Connecting to $ip:$port, target $url, this hostname $host\n";
  26. # Open socket
  27. $sock = @fsockopen($ip, $port, $errno, $errstr, 5);
  28. if ($errno == 0 ) {
  29. $output .= "Connected\n";
  30. # Send payload
  31. $request = "GET $url HTTP/1.0\r\n";
  32. # $request .= "Proxy-Connection: Keep-Alive\r\n";
  33. # $request .= "Pragma: no-cache\r\n";
  34. # $request .= "Host: ".$url."\r\n";
  35. # $request .= "User-Agent: MediaWiki open proxy check\r\n";
  36. $request .= "\r\n";
  37. @fputs($sock, $request);
  38. $response = fgets($sock, 65536);
  39. $output .= $response;
  40. @fclose($sock);
  41. } else {
  42. $output .= "No connection\n";
  43. }
  44. }
  45. $output = escapeshellarg( $output );
  46. #`echo $output >> /home/tstarling/open/proxy.log`;