This script allows you to see where a TinyUrl will go before you click it on.
If you wanted to check where http://tinyurl.com/1 redirected you could type either:
1) /tinyurl 1
or
2) /tinyurl http://tinyurl.com/1
The result either way would be:
alias tinyurl {
sockopen tinyurl_check tinyurl.com 80
sockmark tinyurl_check $gettok($1,1,61)
}
on *:sockopen:tinyurl_check:{
echo 2 -a * Getting information for http://tinyurl.com/ $+ $sock($sockname).mark
timertinyurlcheck 1 20 echo 2 -a * There appears to be no redirect for http://tinyurl.com/ $+ $sock($sockname).mark
sockwrite -n $sockname GET /preview.php?num= $+ $sock($sockname).mark HTTP/1.0
sockwrite -n $sockname Host: tinyurl.com
sockwrite -n $sockname $crlf
}
on *:sockread:tinyurl_check:{
var %x
sockread -f %x
if (<blockquote><b> isin %x) {
timertinyurlcheck off
echo 2 -a * http://tinyurl.com/ $+ $sock($sockname).mark redirects to $remove(%x,<blockquote><b>,<br /></b></blockquote>)
}
}
Cool, I really like the idea. :-)
Though your script works, I thought you can use some regex to make your sockread event a little shorter and add some error checks.
on *:sockread:tinyurl_check:{
var %x
sockread -f %x
if (<blockquote><b> isin %x) {
timertinyurlcheck off
echo 2 -a * http://tinyurl.com/ $+ $sock($sockname).mark redirects to $remove(%x,<blockquote><b>,<br /></b></blockquote>)
}
}
can be rewritten as:
on *:sockread:tinyurl_check:{
sockread %x
if ($regex(%x,<blockquote><b>(.*)<br /></b></blockquote>)) { echo -a $+(http://tinyurl.com/,$sock($sockname).mark) redirects to $regml(1) }
elseif (class="intro"> isin %x) { echo -a * There appears to be no redirect for $+(http://tinyurl.com/, $sock($sockname).mark) }
}
I wouldn't use timers to check socket results, as sockets are quite (unbelievably) fast.
Instead of timers, resort to a unique tag that you will not find in a normal, working page. As the tags class="intro"> used in the code above, can be used to differentiate the two. You also don't need var %variable in the beginning of the sockread event.
Thus, you can remove
timertinyurlcheck 1 20 echo 2 -a * There appears to be no redirect for http://tinyurl.com/ $+ $sock($sockname).mark
in the sockopen event.
I would also use a unique variable such as %tinyurl in this case, to prevent errors.
Although regex may seem complicated, in larger scripts, they will prove quite worthy. Most of all, they can shorten repetitiveness in scripts and even hasten them.
And yes, a Hotlink -> Echo would be nice.
On a second note, please make sure your code works.
2) /tinyurl http://tinyurl.com/1 does not work.
sockmark tinyurl_check $gettok($1,1,61)
as specified in the alias means that you are getting the first token separated by equal signs =. In TinyURL links, there are no = signs in the URL.
And if you are going to use timers, put a dot . in front of them so they are silent.
Here's a rewrite of yours that works both ways as > If you wanted to check where http://tinyurl.com/1 redirected you could type either:
1) /tinyurl 1
or
2) /tinyurl http://tinyurl.com/1
The result either way would be:
alias tinyurl {
if ($sock(tinyurl)) sockclose tinyurl
sockopen tinyurl tinyurl.com 80
sockmark tinyurl $iif($gettok($gettok($1,2,46),2,47),$v1,$1)
}
on *:sockopen:tinyurl: {
echo -a * Getting information for $+(http://,$sock(tinyurl).addr,/,$sock(tinyurl).mark)
sockwrite -n $sockname GET /preview.php?num= $+ $sock(tinyurl).mark HTTP/1.0
sockwrite -n $sockname Host: tinyurl.com $+ $crlf $+ $crlf
}
on *:sockread:tinyurl: {
sockread %tinyurl
if ($regex(%tinyurl,<blockquote><b>(.*)<br /></b></blockquote>)) {
echo -a * $+(http://tinyurl.com/,$sock(tinyurl).mark) redirects to $regml(1)
}
elseif (class="intro"> isin %x) {
echo -a * There appears to be no redirect for $+(http://tinyurl.com/,$sock($sockname).mark)
}
unset %tinyurl
}