Autor: @The_Swash
Descripción : Un acortador de url que la obtiene de goo.gl
Leer más...
Descripción : Un acortador de url que la obtiene de goo.gl
#----------------------------------------------------------
# Obtener URL acortada mediante http://goo.gl
# Programador: The Swash
# Agradecimientos: Psymera, 11Sep, [Zero] y todo h-sec
# Website: http://h-sec.org
#----------------------------------------------------------
import socket, urllib, re
def GetGooURL(url):
header = ['POST /api/shorten HTTP/1.1\r\n',
'Host: goo.gl\r\n',
'Content-Type: application/x-www-form-urlencoded;charset=utf-8\r\n',
'Content-Length: 41\r\n',
'Connection: close\r\n\r\n',
'URLENCODE']
if re.match('^http://', url):
url2 = url
else:
url2 = 'http://' + url
address = socket.gethostbyname('goo.gl')
link = urllib.urlencode({'url':url2})
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
header[5] = link + '&security_token\r\n'
length = len(header)
try:
sock.connect((address,80))
for i in range(length):
sock.send(header[i])
buff = sock.recv(1024)
except:
return 'Error de conexion'
sock.close()
data = re.findall('Location: (.+)\r\n', buff)
return data[0]
url = GetGooURL('h-sec.org')
print url
raw_input()