How to use sockets in Lua to telnet?

1.5k views Asked by At

In Lua, I downloaded the LuaSocket library and then am trying to:

  1. Connect using telnet
  2. Send some commands
  3. receive output from the commands to parse later
  4. close telnet

What am I doing wrong with this code that is not making that work?

local socket = require("socket")
conn = socket.tcp() 
conn:connect("IP Address",23)
conn:send("password") 
conn:send("enable") 
conn:send("password2") ;; above was all login procedure
conn:send("sh run interfaces ethernet 16")
var1 = conn:receive('*l')
print (var1)

I expected this to give me the first line of code printed off by the sh run interfaces ethernet 16 command, but all I get is 2:) 2v sqrt:) sqrt<3... That is, four random symbols that I don't know what they mean.

Any help on what I did wrong here would be greatly appreciated, thanks.

here are those four symbols: enter image description here

1

There are 1 answers

0
Collin Meaney On

Update: For all who were curious I needed \r to make the commands go on separate lines, and I had to put a sleep time in between each of the commands so the system would have time to load in between them. It then worked perfectly.