I can telnet from my MacBook to. an Ubuntu machine like so:
ā telnet 192.168.0.107
Trying 192.168.0.107...
Connected to 192.168.0.107.
Escape character is '^]'.
nx login: user
Password:
Last login: Mon Jan 10 08:26:21 EET 2022 from 192.168.0.104 on pts/4
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 4.9.201-tegra aarch64)
...
user@konalantie-nx:~$
So I try and use the telnet crate to make a telnet connection starting with the example codes here: https://crates.io/crates/telnet
Well, it connects without error and I get events coming back but I never see any data event come back. I'm expecting a login prompt or some such.
So I start pulling apart the received events and end up with this:
fn main() {
let address: String = "192.168.0.107".to_string();
let port: u16 = 23;
let address = SocketAddr::new(
IpAddr::V4(Ipv4Addr::from_str(&address).expect("Invalid address")),
port,
);
println!("Openning telnet connection to: {}", address);
let mut telnet = Telnet::connect(address, 256).expect("Couldn't connect to the server...");
loop {
println!("Writing to telnet connection");
let buffer = "ls\n".as_bytes();
telnet.write(&buffer).expect("Write Error");
println!("Waiting for data on telnet connection");
let event = telnet
.read_timeout(Duration::new(5, 0))
.expect("Read Error");
println!("Got telnet event: {:?}", event);
match event {
Event::Data(data) => {
println!("1 ***: {:?}", data);
}
Event::UnknownIAC(_iac) => {
println!("2: ");
}
Event::TimedOut => {
println!("5: ");
}
Event::NoData => {
println!("6: ");
}
Event::Error(_telnet_error) => {
println!("7: ");
}
Event::Negotiation(Action::Will, TelnetOption::Compress2) => {
telnet
.negotiate(&Action::Do, TelnetOption::Compress2)
.expect("Compress2 option failed");
}
Event::Subnegotiation(TelnetOption::Compress2, _) => {
telnet.begin_zlib();
}
Event::Negotiation(_action, _telnet_option) => {
println!("8: ");
}
Event::Subnegotiation(_telnet_option, _buffer) => {
println!("9: ");
}
}
}
}
Which outputs:
Openning telnet connection to: 192.168.0.107:23
Writing to telnet connection
Waiting for data on telnet connection
Negotiation(Do, TTYPE)
Got telnet event: Negotiation(Do, TTYPE)
8:
Writing to telnet connection
Waiting for data on telnet connection
Negotiation(Do, TSPEED)
Got telnet event: Negotiation(Do, TSPEED)
8:
Writing to telnet connection
Waiting for data on telnet connection
Negotiation(Do, XDISPLOC)
Got telnet event: Negotiation(Do, XDISPLOC)
8:
Writing to telnet connection
Waiting for data on telnet connection
Negotiation(Do, NewEnvironment)
Got telnet event: Negotiation(Do, NewEnvironment)
8:
Writing to telnet connection
Waiting for data on telnet connection
TimedOut
Got telnet event: TimedOut
5:
Writing to telnet connection
...
...
No sign of any data events, even though I am writing a "ls" command successfully.
Am I missing some telnet negotiation?
Anyone have any ideas?