I'm trying to write a C library that connects and talks to a robot which has a telnet server.
The server info is the following:
- user:
as
- ip:
192.168.0.1
- port:
23
- it has no password
In the robot_init() function I'd like to connect to the robot, and I'd expect the following code to do it:
FILE *telnet = popen("telnet -l as 192.168.0.1 23", "w");
From man telnet
:
SYNOPSIS
telnet [-468ELadr] [-S tos] [-b address] [-e escapechar] [-l user]
[-n tracefile] [host [port]]
[...]
-l user
Specify user as the user to log in as on the remote system. This
is accomplished by sending the specified name as the USER envi‐
ronment variable, so it requires that the remote system support
the TELNET NEW-ENVIRON option. This option implies the -a option,
and may also be used with the open command.
However, before writing the C code, I tried to set up a telnet server in a docker container and talk to it through another docker as a client.
To run the server:
sudo docker container run --name telnet-server --publish 2323:23 --detach --restart unless-stopped secobau/telnetd:alpine-1.1
This server has user = user
; ip = 172.17.0.1
; port = 2323
; and no password.
To run the client:
sudo docker run --interactive --tty --name=telnet-client debian:testing bash
apt-get update
apt-get install telnet --yes
telnet -l user 172.17.0.1 2323
I'd expect this to give me an already logged in telnet conection (or at least ask me for the password directly), but instead it keeps asking for a login.
Is it a bug in telnet? How should I automate this?
If telnet -l
doesn't work I think I'll have to write through the pipe something like:
fprintf(telnet, "as\n"); // user
fprintf(telnet, "\n"); // password (no password)
apt-get install telnet --yes
results inE: Unable to locate package telnet
apt-get update
line