问题
I am using sockets to connect to Coral devboard. I want to connect to the devboard and execute a classification script. Whenever I execute my code (lines below) , it shows "In [3]:" for around 10 seconds as if waiting for something. Then "In [4]" appears. What is it happening? I already sent the user and password.
This is my code:
import socket
TCP_IP = '172.16.1.11'
TCP_PORT = 22
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(b'login')
print(s.recv(BUFFER_SIZE).decode())
s.send(b'mendel')
print(s.recv(BUFFER_SIZE).decode())
s.send(b'Password')
print(s.recv(BUFFER_SIZE).decode())
s.send(b'password')
print(s.recv(BUFFER_SIZE).decode())
THIS IS WHAT IS SHOWN IN THE CONSOLE
In [3]: runfile('C:/Users/Coral/Classification/demo_socket.py', wdir='C:/Users/Coral/Classification')
SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2
In [4]:
EDIT
When I am using:
ssh mendel@172.16.1.11
I am already talking to the SSH server. Whay can't I just write the login and password using python instead of writing it with my fingers?
回答1:
I solved it using "paramiko".
import paramiko
#Server's data
IP = '172.16.2.47'
PORT = 22
USER = 'mendel'
PASSWORD = 'mendel'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = IP, port=PORT, username = USER, password = PASSWORD)
stdin, stdout, stderr = ssh.exec_command('hostname -I')
output = stdout.readlines()
type(output)
print('\n'.join(output))
'''
来源:https://stackoverflow.com/questions/62388913/how-to-use-sockets-to-send-user-and-password-to-a-devboard-using-ssh