#!/usr/bin/perl # Author: Kevin P. Inscoe . # File: tinyurl_com.pl # Date of creation: June 30, 2003. # Warranty: None expressed or implied. # License: The Open Software License. V1.1 http://www.opensource.org/licenses/osl.php # # OSI Certified Open Source Software. http://www.opensource.org/licenses/ # # Prerequisites: Perl 5.004 (minimum). # The purpose of this program is find the latest url Tinyurl.com is handing out # Requirements require 5.004; use strict; use LWP::UserAgent; use HTTP::Request::Common "POST"; use String::Random; #Turn off Perl buffering $| = 1; # Globals my $URL = "http://tinyurl.com/create.php"; # Locals my $revision="1.0"; my $progname = "tinyurl_com.pl"; # First generate a dummy url so we always get a new issue from tinyurl.com my $foo = new String::Random; my $urlfoo = $foo->randpattern("sssssssssssssssssssssssssssssssssssssssssssssssssss"); my $url = "http://goatse.cx/" . $urlfoo; my $ua = new LWP::UserAgent; $ua->agent("Wofat/0.1" . $ua->agent); #my $req=POST $URL,[url=>$url]; my $res = $ua->request(POST $URL, [url=>$url]); #print "Req->$req\n"; #my $res=$ua->request($req)->as_string; #my $res = $ua->request($req); my $body = $res->content; if ($res->is_success) { # Now locate the assigned url starting with "
http://tinyurl.com/"... my $start = index($body,"
http://tinyurl.com/"); my $end = $start + 31; my $newstart = index($body,"
",$end); my $len = $newstart - $start - 12; $newstart = $start + 12; my $tmp = substr($body,$newstart,$len); print "$tmp\n"; } else { print "Could not retrieve remote site. " . $res->status_line . "\n"; }