def run(self): try: self.downloaded = os.path.getsize(self.filename) except OSError: self.downloaded = 0 self.start_pointer = self.ranges[0] + self.downloaded if self.start_pointer >= self.ranges[1]: print '%s has been over.' % self.filename return types = urllib.splittype(self.url) host, res = urllib.splithost(types[1]) h = HTTP() h.connect(host) h.putrequest('GET', res) h.putheader('Host', host) h.putheader('Range', "bytes=%d-%d" % (self.start_pointer, self.ranges[1])) h.endheaders() response = h._conn.getresponse() data = response.read(self.once_buffer) while data: file_opener = open(self.filename, 'ab+') file_opener.write(data) file_opener.close() self.downloaded += len(data) data = response.read(self.once_buffer) h.close()
def identify(host): h = HTTP(host) h.putrequest('GET', 'http://%s/' % host) h.putheader('Accept', '*/*') h.endheaders() errcode, errmsg, response = h.getreply() h.close() patterns.attempts = response.headers try: str = response['server'] except: str = None return (str, None)
def gethttpfile(url, size=1024 * 1024): from urllib import splithost from httplib import HTTP if not url.startswith('http:'): raise ValueError, "URL %s" % url host, selector = splithost(url[5:]) h = HTTP(host) h.putrequest('GET', url) h.endheaders() h.getreply() res = h.getfile().read(size) h.close() return res
def gethttpfile(url, size=1024*1024): from urllib import splithost from httplib import HTTP if not url.startswith('http:'): raise ValueError, "URL %s" % url host, selector = splithost(url[5:]) h = HTTP(host) h.putrequest('GET', url) h.endheaders() h.getreply() res = h.getfile().read(size) h.close() return res
from urllib import splithost from httplib import HTTP if os.path.exists("/dev/shm"): TMPDIR = "/dev/shm" else: TMPDIR = "/tmp" TMPDIR += "/hda-analyzer" print "Using temporary directory: %s" % TMPDIR print "You may remove this directory when finished or if you like to" print "download the most recent copy of hda-analyzer tool." if not os.path.exists(TMPDIR): os.mkdir(TMPDIR) for f in FILES: dest = TMPDIR + '/' + f if os.path.exists(dest): print "File cached " + dest continue print "Downloading file %s" % f host, selector = splithost(URL[5:]) h = HTTP(host) h.putrequest('GET', URL + f) h.endheaders() h.getreply() contents = h.getfile().read(2 * 1024 * 1024) h.close() open(dest, "w+").write(contents) print "Downloaded all files, executing %s" % FILES[0] os.system("python2 %s" % TMPDIR + '/' + FILES[0] + ' ' + ' '.join(sys.argv[1:]))
import sys from urllib import splithost from httplib import HTTP if os.path.exists("/dev/shm"): TMPDIR="/dev/shm" else: TMPDIR="/tmp" TMPDIR += "/hda-analyzer" print "Using temporary directory: %s" % TMPDIR print "You may remove this directory when finished or if you like to" print "download the most recent copy of hda-analyzer tool." if not os.path.exists(TMPDIR): os.mkdir(TMPDIR) for f in FILES: dest = TMPDIR + '/' + f if os.path.exists(dest): print "File cached " + dest continue print "Downloading file %s" % f host, selector = splithost(URL[5:]) h = HTTP(host) h.putrequest('GET', URL + f) h.endheaders() h.getreply() contents = h.getfile().read(2*1024*1024) h.close() open(dest, "w+").write(contents) print "Downloaded all files, executing %s" % FILES[0] os.system("python %s" % TMPDIR + '/' + FILES[0] + ' ' + ' '.join(sys.argv[1:]))