0

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?

enter image description here

Aizzaac
  • 3,146
  • 8
  • 29
  • 61
  • ahh, hard to tell, please give more info. This looks like you are just sending the data, but I'm very suspicious that it is being sent over port 22, that's ssh port. Do you have the code on the server side? – Nam Vu Jun 15 '20 at 14:18
  • The code is in the devboard, isn't it? And when I connect by ssh, I am just sending ```ssh mendel@172.16.1.11``` It should work. – Aizzaac Jun 15 '20 at 14:49
  • I'm sorry? If you are expecting the server to do something, don't you need a client also? Where is the client code? – Nam Vu Jun 15 '20 at 15:08
  • The client code is the one I have written here. – Aizzaac Jun 15 '20 at 15:11
  • when I connect using ssh to the devboard...I am communicating with the SSH server of the devboard. So why when "automating" with python code I cannot just connect? – Aizzaac Jun 15 '20 at 15:12
  • hi again, what exactly is the end goal here? If this is the client code, then where is the server code? You'll definitely need a server setup on the dev board that does something like this: 1) Open a tcp connection on a specific port (your client need to connect to this port, not 22) 2) Wait for client connection 3) Connected to client 4) Wait for command to run from client 5) Run command Right now you're just sending those bytes to the dev board over port 22, that's why you're not getting anything back :) – Nam Vu Jun 15 '20 at 15:29
  • Thr goal is to use python to connect to the board and execute a script. I have tried using the serial port and now with sockets. – Aizzaac Jun 15 '20 at 15:34
  • Check my other question: https://stackoverflow.com/questions/62419187/how-to-execute-commands-in-a-remote-server-using-python – Aizzaac Jun 16 '20 at 23:40

1 Answers1

0

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))
'''


Aizzaac
  • 3,146
  • 8
  • 29
  • 61