1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

GSuggest PHP CLI Script

Discussion in 'PHP & Perl' started by Captain Midnight, Mar 25, 2014.

  1. Captain Midnight

    Captain Midnight Newbie

    Joined:
    Sep 30, 2009
    Messages:
    31
    Likes Received:
    7
    Location:
    USA
    I munged together a php program to rotate through a list of proxy servers and hit Google Suggest for results based on a keyword.

    For example:

    Code:
    # php gs.php tools
    tools
    tools of the trade
    tools plus
    tools for sale
    tools of the mind
    tools and toys
    tools4cheap
    tools independence mo
    toolsnow
    tools for working wood
    The reason why I'm posting it here is because I read someone else has a script here that didn't work very well and the suggestions were to also rotate through proxy severs. Anyway, I though I would share what I munged together:

    PHP:
    <?php
    /*
     * gsuggest - Will use a proxy file to randomize connections for google suggestions results.
     *
     * Create a proxy.list file in the formation of
     *  USERNAME:PASSWORD@IP:PORT
     *  USERNAME:PASSWORD@IP:PORT
     *
     *   Usage:  gsuggest <keyword>
     *
     * Captain Midnight - 03/24/14
     *   
     */

    $proxyuse="true";

    function 
    gsuggest(&$keyword)
    {
      if (isset(
    $keyword) && $keyword !== "") {    

            
    $getcontents=file_get_contents("proxy.list");
            
    $proxydetails=explode("\n",$getcontents);

                    
    $n=-1;

            for(
    $gets=0;$gets<=count($proxydetails);$gets++)
            {

                            
    $exp=explode(":",$proxydetails[$gets]);
                            
    $expa=explode("@",$exp[1]);

                            
    $n++;
                            
    $authentication_keywords[$n]["username"] = $exp[0];
                            
    $authentication_keywords[$n]["password"] = $expa[0];
                            
    $authentication_keywords[$n]["ip"] = $expa[1];
                            
    $authentication_keywords[$n]["port"] = $exp[2];
            }

                    
    $get_auth_keys $authentication_keywords[array_rand($authentication_keywords)];
                    
    $user $get_auth_keys[username];
                    
    $pass $get_auth_keys[password];
                    
    $ips $get_auth_keys[ip];
                    
    $port trim($get_auth_keys[port]);
                    
    $encode=$user.":".$pass;
                    
    /*
                    echo "++++++++++++++++\nDEBUG\n++++++++++++++++\nUSER = $user\nPASS = $pass\nIP = $ips\nPORT = $port\nENCODE = $encode\n";
                    */

                    /* $url = "http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=$keyword"; */
                    
    $url "http://clients1.google.com/complete/search?output=toolbar&hl=en&q=$keyword";
                    
    $str str_replace(" ""+",$url);

            
    /* if($_REQUEST['proxyuseset']) */
            
    if (isset($proxyuse) && $proxyuse == "true") {
                            
    $ch curl_init();
                    
    curl_setopt($chCURLOPT_URL$str);
                    
    curl_setopt($chCURLOPT_HEADER0);
                    
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
                    
    curl_setopt($chCURLOPT_PROXYPORT$port);
                    
    curl_setopt($chCURLOPT_PROXYTYPE'HTTP');
                    
    curl_setopt($chCURLOPT_PROXY$ips);
                    
    curl_setopt($chCURLOPT_PROXYUSERPWD$encode);
                     
    $data = (curl_exec($ch));
                     
    curl_close($ch);
            } 
    /* proxyset */
            
    else {
                    
    $ch curl_init();
                    
    curl_setopt($chCURLOPT_URL$str);
                    
    curl_setopt($chCURLOPT_HEADER0);
                    
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
                     
    $data curl_exec($ch);
                     
    curl_close($ch);
                     
    $ips" ";
            }
    /* noproxyset */

            
    $xml simplexml_load_string("$data");

        foreach (
    $xml->children() as $child) {                               
          foreach (
    $child->suggestion->attributes() as $dta) {                                        
          echo 
    $dta."\n";                    
          }
        }
      } 
    /* keyword set */
    /* function */

    gsuggest($argv[1]);

    ?>
     
    • Thanks Thanks x 2
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    950
    Likes Received:
    662
    Occupation:
    Web/Bot Developer
    Gotta love CLI's. 80% of the code I write is command-line interface.

    Remember if you want to run this as a shell script in linux/unix systems you need to include the path to your PHP CLI binary at the top of the file. This path may differ depending on your system.
    Code:
    #!/usr/bin/php
     
    Last edited: Mar 25, 2014