lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I’m new to lua.

 

I’m trying to script a session against a telnet server (login, run a few commands within a menu-driven interface, then close the session).

 

I’m using lua sockets. My code appears below.

 

I’m not getting the expected results, though the code seems to run OK.

 

I’m trying to figure out how I can “see” what’s going on during the session.

 

Is there a way in lua to echo back the server responses, for example?

 

Thanks very much for any thoughts or suggestions.

 

 

 

require 'socket'

local port = 23

local host = "hostname"

local conn = socket.connect(host, port)

socket.sleep (3)

local assert (conn:send ("user\n"))

socket.sleep (1)

local assert (conn:send("password\n"))

socket.sleep (1)

local assert (conn:send("a\n"))

socket.sleep (1)

local assert (conn:send("p\n"))

socket.sleep (1)

local assert (conn:send(" \n"))

socket.sleep (1)

local assert (conn:send("y\n"))

socket.sleep (1)

local assert (conn:send("s\n"))

socket.sleep (1)

local assert (conn:send("email@address.edu\n"))

socket.sleep (1)

local assert (conn:send("lua test\n"))

socket.sleep (1)

local assert (conn:send("lua test message\n"))

socket.sleep (1)

local assert (conn:send("^E\n"))  (ed. note: not sure if this is the correct way to send a ctrl-E. Also tried \005 )

socket.sleep (1)

local assert (conn:send("s\n"))

socket.sleep (1)

local assert (conn:send(" \n"))

socket.sleep (1)

local assert (conn:send("q\n"))

socket.sleep (1)

local assert (conn:send("q\n"))

socket.sleep (1)

local assert (conn:send("x\n"))

socket.sleep (1)

conn:close()

 

 

Wade