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

[GET] Mass URL shortening script (PHP)

Discussion in 'Black Hat SEO Tools' started by itz_styx, Sep 24, 2015.

  1. itz_styx

    itz_styx Jr. VIP Jr. VIP

    Joined:
    May 8, 2012
    Messages:
    381
    Likes Received:
    141
    Occupation:
    CEO / Admin / Developer
    Location:
    /dev/mem
    Home Page:
    here is a little script to run a url through "yourls" url shortening services.
    it will output a list of shortened urls - free 301 redirects ;)
    these sites run on the YOURLS platform (yourls.org).
    i wrote this quickly in like 10 mins a few years ago, but it still works fine.
    it can also output all urls in spintax and removes bad hosts automatically.


    Code:
    <?php
        // YOURLS - URL shortening script for bhseos.com 
        // by styx @ argo-content.com 2011
    
    
        if(empty($argv[2])) usage($argv[0]);
        $fl=$argv[1]; // list file
        $f=file($fl); // don't touch this!
        $url=urlencode($argv[2]);
        $verbose=0; // show more detailed output, 0 = disabled | 1 = enabled
        $spin=1; // output the urls as spintax, 0 = disabled | 1 = enabled
        function curl($url,$postdata=NULL)
        {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0');
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
            curl_setopt($curl, CURLOPT_AUTOREFERER, true);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_COOKIESESSION, FALSE);
            curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie");
            curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie");
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
            curl_setopt($curl, CURLOPT_TIMEOUT, 10);
            curl_setopt($curl, CURLOPT_POST, TRUE);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
            $html = curl_exec($curl);
            curl_close($curl);
            return $html;
        }
    
    
        function delLine($list,$line){
            if(!is_writable($list)) {
                die("x $file isn't writable.\n");
            } else {
                $arr = file($list);
            }
            if($fp=fopen($list,'w+')) {
                foreach($arr as $ln) {
                    $match=trim($ln);
                    if(!stristr($line,$match)) {
                        fwrite($fp,$ln);
                    }
                }
                fclose($fp);
            } else {
                die("x coudln't open $file! check permissions.");
            }
        }
    
    
        function remove_host($host,$list) {
            $fa = file($list);
            foreach ($fa as $f => $l) {
                if(stristr($l,$host)) {
                    delLine($list,trim($l));
                    break;
                }
            }
        }
    
    
        function main() {
            global $f,$fl,$url,$verbose,$spin;
            $sz=count($f);
            if($spin==1) print "{";
            foreach($f as $n => $l) {
                $host=trim($l);
    
    
                if($verbose==1&&$spin==0) { // only print this if spintax is disabled..
                    print "(".($n+1)."/$sz) current host: $host | ";
                }
                $query="url=$url&keyword=";
                $html = curl($host,$query);
                preg_match_all("/copylink\" class=\"text\" size=\"40\" value=\"(.*)\"/i",$html,$m);
                if(!empty($m[1][0])) {
                    $lnk=$m[1][0];
                    if($spin==0) {
                        print $lnk."\n";
                    } else {
                        if($n<($sz-1)) {
                            print $lnk."|";
                        } else {
                            print "$lnk";
                        }
                    }
                } else {
                    if($verbose==1&&$spin==0) print "- removing host: $host\n";
                    remove_host($host,$fl);
                }
            }
            if($spin==1) print "}\n";
        }
    
    
        function usage($arg) {
           die("mass url shortening script by styx @ bhseos.com\nusage: <list> <url>\nexample: php $arg list.txt http://argo-content.com\n");
        }
        main(); // execute
    ?>
    

    usage:


    you need to run this from the linux (or other *nix) shell like:


    Code:
    php shorten.php targets.txt http://yourdomain.com

    to enable verbose and/or spintax output, change the variables on top of the script:


    Code:
    $verbose=0; // show more detailed output, 0 = disabled | 1 = enabled
    $spin=1; // output the urls as spintax, 0 = disabled | 1 = enabled
    

    and here some working hosts.. just a few, scrape your own ;) :


    Code:
    http://activ.me
    http://jdivert.com
    http://j.plustar.jp
    http://macp.ro
    http://onj.me
    http://rct.me
    http://urim.sourceforge.net
    

    here are some example footprints to find sites:


    Code:
    intitle:"yourls -- your own url shortener" 
    or
    "powered by Yourls"
    

    thought i'd share it with you guys :)
     
    • Thanks Thanks x 2
  2. NickyOktavian

    NickyOktavian BANNED BANNED

    Joined:
    Feb 6, 2013
    Messages:
    269
    Likes Received:
    52
    Thanks for share brother! let me try...
     
  3. itz_styx

    itz_styx Jr. VIP Jr. VIP

    Joined:
    May 8, 2012
    Messages:
    381
    Likes Received:
    141
    Occupation:
    CEO / Admin / Developer
    Location:
    /dev/mem
    Home Page:
    no problem, hope you have a use for it :)