Public feed #888456

Stuff

public text v1 · immutable
Raw Edit
·published 2008-02-02 03:30 UTC
rendered paste body
<?php

/*
      _______________________
   ///////______________________\\\\\\\
             Author: PaT
        Irc: irc.pseud0.net #pseud0 #coder-pat
   \\\\\\\¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯///////
      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
      
      just run 'php script.php' in your terminal.
*/

   set_time_limit(0);
   error_reporting(0);

function usage(){
   $a = $_SERVER['argv'][0];
      if ( eregi('/', $a) ){
         $b = explode('/', $a);
         $x = count($b)-1;
         $a = $b[$x];
      }else
      if ( eregi('\\', $a) ){
         $b = explode('\\', $a);
         $x = count($b)-1;
         $a = $b[$x];
      }
      
      echo "\nUsage: $ php $a host [port] [times] [delay] [data] [options]\n\n".
          "Options:\n--silent [does not display socket info.]\n".
          "--nodataret [does not return the 120 bytes of data when received.]\n\n".
          "Default values for optional arguments:\n".
          "port [80]\n".
          "times [100]\n".
          "delay [0] in seconds".
          "data = GET / HTTP/1.1\nAccept: */*\nHost: {HOST}\n\n"
          ;
}

if ($_SERVER['argc'] >= 2){
   $host = $_SERVER['argv'][1];
   if ($_SERVER['argv'][2] == ''){
      $port = 80;
   }else{ $port = $_SERVER['argv'][2]; }
   
   if ($_SERVER['argv'][3] == ''){
      $times = 10;
   }else{ $times = $_SERVER['argv'][3]; }
   
   if ($_SERVER['argv'][4] == ''){
      $delay = '';
   }else{ $delay = $_SERVER['argv'][4]; }
   
   if ($_SERVER['argv'][5] == ''){
      $data = "GET / HTTP/1.1\nAccept: */*\nHost: $host\n\n";
   }else{ $data = $_SERVER['argv'][5]; }
   
   foreach ($_SERVER['argv'] as $val){
      if ($val == '--nodataret'){
         $nodataret = 1;
      }
      if ($val == '--silent'){
         $silent = 1;
      }
   }
   
   
   $s = array();
   $r = array();
   
   echo "$host $port $times $delay $data\n";

   for ($i = 1; $i <= $times; $i++){
      $s[$i] = fsockopen($host, $port);
         if($s[$i]){
            if ($silent == 1){}else{
               echo "sending $i\n";
            }
            fwrite($s[$i], $data, strlen($data));
            if ($nodataret == 1){}else{
               $out = fread($s[$i], 120);
            }
            if ($silent == 1){}else{
               echo "$out\n";
            }
            if (($delay == '') || ($delay == 0)){}else{ sleep($delay); }
            
         }
   }   
   
   echo "\nFinished [$host:$port]\n";
}else
{
   usage();
}
?>