Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: The Swash en 2 Noviembre 2011, 03:35 am



Título: [Python] Little Script Codepad
Publicado por: The Swash en 2 Noviembre 2011, 03:35 am
Código
  1. #------------------------------------------------------------------------------
  2. # Pequeño script de escritorio para utilizar Codepad.org
  3. # Programmer: The Swash
  4. # Website: http://h-sec.org
  5. #------------------------------------------------------------------------------
  6.  
  7. import urllib, urllib2, re
  8.  
  9. def GetResponse(lang, code):
  10.    code = urllib.urlencode({'lang':lang, 'code':code,'run':'True','submit':'Submit'})
  11.    web = urllib2.urlopen('http://codepad.org',code)
  12.    source = web.read()
  13.  
  14.    resp = re.findall('<td width="100%" style="vertical-align: top">\n<div class="highlight">\n<pre>\n([^\b]+)</pre>', source)
  15.    temp = resp[0]
  16.    if re.findall('<a href="#line-[\d]">(.+)</a>', temp):
  17.        err = re.findall('<a href="#line-[0-9]">(.+)</a>', temp)
  18.        val = re.sub('<a href="#line-[0-9]">(.+)</a>', err[0], temp)
  19.        return val
  20.    else:
  21.        return temp
  22.  
  23. langs = ('Python','C','C++','PHP','Perl','Ruby')
  24. lang = 0
  25. print "Bienvenido, lenguajes disponibles: \n"
  26. length = len(langs)
  27. for i in range(length):
  28.    print str(i+1) + '- ' + langs[i]
  29.  
  30. while not((ord(str(lang)) >= 49) and (ord(str(lang)) <= 54)):
  31.    print "Elige el numero correspondiente: "
  32.    lang = input()
  33.  
  34. try:
  35.    path = raw_input("Ingrese la ubicacion completa del archivo: ")
  36.    lfile = open(path, "r")
  37.    buff = lfile.read()
  38.    lfile.close()
  39.  
  40. except:
  41.    print "Error al procesar archivo"
  42.    exit()
  43.  
  44. Resp = GetResponse(langs[lang-1], buff)
  45. print "Output:\n"
  46. print Resp
  47. raw_input("Presione enter para salir..")

Un pequeño script para gestión con Codepad.
Acepto críticas.

Un saludo.