def run(self): printer.printDebug (self.opts, "processo tar partito") # First make a copy of the output folder fname = "demo.out.%s.tgz" % (time.strftime("%d.%m.%Y_%H-%M")) #TODO check how to send in bg stdout # os.spawnv(os.P_NOWAIT, "/sw/bin/tar", ["tar", "cvzf", fname, "demo.out"]) retc = call(["tar", "cvzf", fname, "demo.out"], stdout = file("/dev/null", 'w')) printer.printDebug(self.opts, "processo tar finito")
def traceRoute(self): cmd = "traceroute -I -n -f 5 -q 1 %s | tail -n 1 | awk '{print $1}'" % self.address # XXX try except block needed res = None while True: try: printer.printDebug (self.opts, "traceroute!") res = Popen(cmd, stdout=PIPE, shell=True).communicate()[0].rstrip() break except OSError, e: if e.errno == errno.EINTR: print "Error traceroute" continue else: raise
def run(self): rtt = None hop = None cap = None # print "partito %s" % self.address cmd = "./ping -c 20 -i 0.5 -t 30 %s " % self.address while True: try: printer.printDebug (self.opts, "ping %s!" % self.address) p = Popen(cmd, shell=True, stdout=PIPE) break except OSError, e: if e.errno == errno.EINTR: print "Error ping" continue else: raise
def run(self): printer.printDebug(self.opts, "Thread partito!") import urllib2 # To not hang up with this thread, there's a limited number of tries tries = 3 got = False ip = "0.0.0.0" while tries > 0 and not got: try: printer.printDebug(self.opts, "trying to acquire pubip") # Comment out this line if you want to skip the request and # fill ip var with the value you want (must be in four dotted notation) ip = urllib2.urlopen("http://api.externalip.net/ip/").read() # ip = urllib2.urlopen("https://vinrouge.enst.fr/~paolo/pubip.php").read() print "Public ip: ", ip if ip != None: got = True except Exception,e: print "failed: tries left: %d" % (tries,) print e tries -= 1
res = self.C_re.search(line) if res: cap = res.groups()[0] res = self.rtt_re.search(line) if res: rtt = res.groups()[0] break except OSError, e: if e.errno == errno.EINTR or e.errno == 0: continue else: raise except IOError, e: printer.printDebug(self.opts, "Errore n %d" % e.errno) continue self.peer.CAP = cap # self.peer.HOP = hop #XXX only for windows peers self.peer.RTT = rtt status = p.wait() if (hop and hop > 50) or not hop: # print "High HOP peer, running traceroute..." self.traceRoute() # print "finished tracerouting!" else: self.peer.HOP = hop #XXX only for windows peers self.peer.CapPstaus = status