Ejemplo n.º 1
0
def testSSH():
    
    #find the default gateway
    #
    default_gateway = gatewayIP()

    rtrn = 7
 
    while(rtrn != 0):
        # prompt user for password
        #
        user_pwd = getpass.getpass("\nRouter Password >> ")

        # save to a file for sshpass  
        #
        #with open("user_pwd.txt", "wt") as f:
        #    f.write(user_pwd)

        # validate the password
        #
        rtrn = call(['sshpass', '-p', user_pwd, \
            'ssh', '-p', '2222', \
            'root@' + default_gateway, "exit"]) 

        if ( rtrn == 5 ):
            print("Authentication Failed. Re-enter Password for Router.")

        elif ( rtrn == 6 ):
            print("RSA Fingerprint not verified. Please Try Again.")
            rtrn = call(['ssh', '-p', '2222', 'root@' +default_gateway, "exit 1"])

    return (user_pwd)
Ejemplo n.º 2
0
    def attemptFindServer(self, toiServerPORT=5005):
        # Get a list of IPs running Toi-Chat software on the mesh network
        #
        listIPs = conn_router(gatewayIP(), self.user_pwd)
        self.logger.debug("List of returned IPs: " + str(listIPs))
        # Check to see if there are any IPs in the returned ARP list
        #
        if listIPs == None:
            return 0

        # Sort the list of IPs be increasing distance
        #
        sortIPs = pingIPSort(listIPs)[0]

        # Create a request DNS information request message
        #
        requestDNS = self.createRequestDnsMessage()
        self.logger.debug("List of potential TOIChat Hosts:" + str(sortIPs))

        for toiServerIP in sortIPs:
            # Print to stdout what we are trying to connect to
            #
            self.logger.debug("Trying to connect to '" + str.strip(toiServerIP) + "'.")
            try:
                self.myToiChatClient.sendMessage(toiServerIP, requestDNS, toiServerPORT)
            except Exception as e:
                if toiServerIP == sortIPs[len(sortIPs) - 1]:
                    # We tried all IPs in the list and could not connect to
                    # any. Return error to stdout informing the user
                    self.logger.warning(
                        "Could not connect to '"
                        + str.strip(toiServerIP)
                        + "'. Exited with status: "
                        + str(e)
                        + ". Exhausted known list of hosts."
                    )
                    return 0
                else:
                    self.logger.info(
                        "Could not connect to '"
                        + str.strip(toiServerIP)
                        + "'... Exited with status: "
                        + str(e)
                        + "Trying next IP in list."
                    )
                    continue
            # Did not fail to connect. Connection to server successful
            # Break out of for loop
            #
            break
        return 1
Ejemplo n.º 3
0
def listen_router(user_pwd):
    # Find the default gateway
    # 
    default_gateway = gatewayIP()

    scriptPath = "../etc/router_tx_arpinfo.sh"

    # Run '../router-scripts/router_tx_arpinf.sh' on local router
    #
    ssh = subprocess.Popen(['sshpass', '-p', user_pwd, \
        'ssh', '-p', '2222', \
        'root@' + default_gateway, "sh "  + scriptPath, '&'], \
        shell=False, \
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)