Example #1
0
 def close(self):
     self.p.stdin.close()
     self.p.stdout.close()
     self.p.stderr.close()
     self.p.terminate()
     self.p.wait()
     log.info("Process {} exited with code {}".format(
         green(self.p.pid), green(self.p.returncode)))
Example #2
0
 def __init__(self, host, port, timeout=5):
     super(remote, self).__init__()
     self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.s.settimeout(timeout)
     self.s.connect((host, port))
     self.host = host
     self.port = port
     log.info("Connecting to {} on port {}".format(green(host),
                                                   green(port)))
Example #3
0
 def recvuntil(self, delim):
     data = self.recv(len(delim), nolog=True)
     while data[-len(delim):] != delim:
         data += self.recv(1, nolog=True)
     log.debug("Received {} bytes\n{}".format(green(len(data)),
                                              hexdump(data)))
     return data
Example #4
0
 def recvall(self):
     data = b""
     try:
         while True:
             data += self.recv(1, nolog=True)
     except:
         log.debug("Received {} bytes\n{}".format(green(len(data)),
                                                  hexdump(data)))
     return data
Example #5
0
 def __init__(self,
              args,
              stdin=subprocess.PIPE,
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE):
     super(process, self).__init__()
     self.p = subprocess.Popen(args,
                               stdin=stdin,
                               stdout=stdout,
                               stderr=stderr,
                               shell=False)
     log.info("Process started with PID {} {}".format(
         green(self.p.pid), args))
Example #6
0
 def send(self, data):
     self.s.sendall(data)
     log.debug("Sent {} bytes\n{}".format(green(len(data)), hexdump(data)))
Example #7
0
 def recv(self, size, nolog=False):
     data = self.s.recv(size)
     if not nolog:
         log.debug("Received {} bytes\n{}".format(green(len(data)),
                                                  hexdump(data)))
     return data
Example #8
0
 def close(self):
     self.s.shutdown(socket.SHUT_RDWR)
     self.s.close()
     log.info("Closed connection with {} on port {}".format(
         green(self.host), green(self.port)))
Example #9
0
	def info(self, msg, details=None):
		if self.level >= 1:
			if details is not None:
				msg += "\n{}\n{}\n{}".format("\u2014"*term.columns, details, "─"*term.columns)
			self.stdout.write("[{}]:  {}\n".format(green("INFO"), msg))
Example #10
0
 def recvline(self):
     data = self.p.stdout.readline()
     log.debug("Received {} bytes\n{}".format(green(len(data)),
                                              hexdump(data)))
     return data
Example #11
0
 def send(self, data):
     self.p.stdin.write(data)
     log.debug("Sent {} bytes\n{}".format(green(len(data)), hexdump(data)))
     self.p.stdin.flush()