def full_rpc(origin_ip, query_id): try: rem = SshMachine(origin_ip, user='******', keyfile='~/.ssh/id_rsa', ssh_opts=["-o StrictHostKeyChecking no", "-o UserKnownHostsFile=/dev/null"]) conn = ssh_connect(rem, 18861) conn.root.exposed_full_response(query_id, 'End Point Reached') except Exception, e: print "Could not perform RPC"
def ssh_connect(sshctx, remote_port): """Connects to the remote server over an SSH tunnel. See :func:`rpyc.utils.factory.ssh_connect`. :param sshctx: the :class:`rpyc.utils.ssh.SshContext` instance :param remote_port: the remote TCP port :returns: an RPyC connection exposing ``SlaveService`` """ return factory.ssh_connect(sshctx, remote_port, SlaveService)
def ssh_connect(remote_machine, remote_port): """Connects to the remote server over an SSH tunnel. See :func:`rpyc.utils.factory.ssh_connect` for more info. :param remote_machine: the :class:`plumbum.remote.RemoteMachine` instance :param remote_port: the remote TCP port :returns: an RPyC connection exposing ``SlaveService`` """ return factory.ssh_connect(remote_machine, remote_port, SlaveService)
def testHost(host, buff): try: try: conn = rpyc.connect(host, 18861) print >> buff, colored('Service Is Exposed Externally', 'red') except: pass #print >> buff, colored("Service Not Exposed Exterally",'green') rem = SshMachine(host, user='******', keyfile='~/.ssh/id_rsa', ssh_opts=["-o StrictHostKeyChecking no", "-o UserKnownHostsFile=/dev/null"]) #print >> buff, colored('SSH Connected', 'green') try: conn = ssh_connect(rem, 18861) #print >> buff, conn.root.test() conn.root.test() except Exception, e: print >> buff, colored('Service is not Running', 'red') print >> buff, 'Attempting to Start Service...' subprocess.call(["ssh", "-t", "-i", "~/.ssh/id_rsa", "-o StrictHostKeyChecking no", "-o UserKnownHostsFile=/dev/null", "ucb_268_measure@%s" % host, "sudo tking-server stop; sudo tking-server start;"], stdout=FNULL, stderr=subprocess.STDOUT) try: sleep(4) conn = ssh_connect(rem, 18861) #print >> buff, conn.root.test() conn.root.test() except: #print >> buff, colored('Could not start service', 'red') return responses = [] def remote_call(): try: response = conn.root.get_latency('ns.nwt.cz','217.197.152.132','ns1.google.com','216.239.32.10') responses.append(response) end_time, start_time, ping_time, address = response #latency = end_time - start_time - ping_time #responses.append((latency, address)) except: response.append(None) threads = [] for i in range(3): t = Thread(target=remote_call) t.start() threads.append(t) for t in threads: t.join() a = responses[0] b = responses[1] c = responses[2] k = conn.root.exposed_get_k('google.com', '8.8.8.8') full = conn.root.exposed_full_test('ns.nwt.cz','217.197.152.132', 'ns1.internetlatencymeasurementstudy.org', '54.214.0.110') print >> buff, "Full:", full print >> buff, "K:", k if type(a[0]) == type('') and type(b[0]) == type('') and type(c[0]) == type(''): print >> buff, colored('Amazon NS maybe inactive, or Node DNS server cannot bind', 'red') print >> buff, a, '\n', b, '\n', c elif a and b and c: print >> buff, colored('Recieved Latencies','green'), '\n', a, '\n', b, '\n', c else: print >> buff, colored ('Other Issue with latencies', 'red'), a, b, c