In Lua, I downloaded the LuaSocket library and then am trying to:
- Connect using telnet
- Send some commands
- receive output from the commands to parse later
- 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:
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.