code_junkie

Slipping podcasts through a filter

Nov 11th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/usr/local/bin/python
  2.  
  3. import cgitb; cgitb.enable()
  4. import cgi
  5. from urllib2 import urlopen
  6.  
  7. def tohex(data):
  8. return "".join(hex(ord(char))[2:].rjust(2,"0") for char in data)
  9.  
  10. def fromhex(encoded):
  11. data = ""
  12. while encoded:
  13. data += chr(int(encoded[:2], 16))
  14. encoded = encoded[2:]
  15. return data
  16.  
  17. if __name__=="__main__":
  18. print("Content-type: text/plain")
  19. print("")
  20. url = fromhex( cgi.FieldStorage()["target"].value )
  21. contents = urlopen(url).read()
  22. for i in range(len(contents)/40+1):
  23. print( tohex(contents[40*i:40*i+40]) )
  24.  
  25. #!/usr/bin/env python2.6
  26. import os
  27. from sys import argv
  28. from urllib2 import build_opener, ProxyHandler
  29.  
  30. if os.fork():
  31. exit()
  32.  
  33. def tohex(data):
  34. return "".join(hex(ord(char))[2:].rjust(2,"0") for char in data)
  35.  
  36. def fromhex(encoded):
  37. data = ""
  38. while encoded:
  39. data += chr(int(encoded[:2], 16))
  40. encoded = encoded[2:]
  41. return data
  42.  
  43. if __name__=="__main__":
  44. if len(argv) < 2:
  45. print("usage: %s URL [FILENAME]" % argv[0])
  46. quit()
  47.  
  48. os.chdir("/home/courtwright/mp3s")
  49. url = "http://example.com/cgi-bin/hex.py?target=%s" % tohex(argv[1])
  50. fname = argv[2] if len(argv)>2 else argv[1].split("/")[-1]
  51. with open(fname, "wb") as dest:
  52. for line in build_opener(ProxyHandler({"http":"proxy.example.com:8080"})).open(url):
  53. dest.write( fromhex(line.strip()) )
  54. dest.flush()
Add Comment
Please, Sign In to add comment