I’m trying to connect to a telnet server that we have. I started off using gen_tcp and while I was able to connect, it wasn’t receiving data like I had hoped so figured I’d give erlangs ct_telnet a try.
I’m new to Elixir so trying to decipher the Erlang docs and figuring out how to translate that into Elixir is a bit of a challenge.
I’m just trying to do a simple open and close right now but I’m getting an error and hoped someone could point me in the right direction.
defmodule UvTel do
def hello do
{:ok, handle} = :ct_telnet.open("127.0.0.1")
IO.inspect(handle)
:ok = :ct_telnet.close(handle)
end
end
** (ArgumentError) argument error
(stdlib) :ets.select(:ct_attributes, [{{:ct_conf, :"$1", :_, :_, :_, "127.0.0.1", :_}, [], [:"$1"]}])
ct_config.erl:576: :ct_config.get_key_from_name/1
ct_telnet.erl:204: :ct_telnet.open/2
(uv_tel) lib/uv_tel.ex:16: UvTel.hello/0
ct_telnet is part of the ct testing framework and not a telnet client library.
Aside of that, :ct_telnet.open/1 takes its first argument of type ct.target_name(), which again is just an alias to atom(), so if at all he has to use :ct_telnet.open(:"127.0.0.1").
I tried that as well, but still get this error. I feel like I’m missing something that correlates a key or name to an ip address and some settings. Not sure.
Well, I’m really just trying a proof of concept to see what can be done. We have a database server (it’s similar to Pick Operating System Database - comes from the 60’s) that we connect to over telnet. I’m just trying to automate some of those tasks and wanted to see what I could accomplish with Elixir. Is there something else I can use? gen_tcp allowed me to connect but I was receiving data in strange ways. I thought maybe ct_telnet was a better choice, but maybe not.
I do not know that database, nor have I worked with it, but for a rough prototype you should be able to use it. But you shouldn’t go with it into production.
Telnet is a character-based protocol, but ct_telnet does only allow to receive proper lines, not single chars. So if you can actually use this depends on your target host.
But perhaps you can build a proper telnet client on top of gen_tcp and publish it on hex.pm?
Aside of that, telnet has only been formalized in 1973, so your target host may speak a dialect that is not widely supported nowadays.