pib / untinyurl

A collection of scripts in various languages to find where a shortened URL redirects to.

This URL has Read+Write access

untinyurl / untinyurl.py
100644 15 lines (12 sloc) 0.379 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import httplib
import urlparse
 
def untinyurl(tinyurl):
    url = urlparse.urlsplit(tinyurl)
    req = urlparse.urlunsplit(('', '', url.path, url.query, url.fragment))
    con = httplib.HTTPConnection(url.netloc)
    try:
        con.request('HEAD', req)
    except:
        return tinyurl
    response = con.getresponse()
    return response.getheader('Location', tinyurl)