Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5de781471
|
||
|
|
d2ad6be236
|
||
|
|
ca65d252c9 | ||
|
|
fc184ea591 | ||
|
|
8a76ca11c9 | ||
|
|
8a3a34efc0 | ||
|
|
996d81129d | ||
|
|
499dfd6843 | ||
|
|
8aa08814a1 | ||
|
|
eaae852961 |
@@ -0,0 +1,60 @@
|
||||
-- Despite the name it's not telnet
|
||||
local component = require("component")
|
||||
if not component.isAvailable("internet") then
|
||||
terminal.write("telnet: this program requires an internet card to run\n")
|
||||
return
|
||||
end
|
||||
|
||||
local internet = component.internet
|
||||
if not internet.isTcpEnabled() then
|
||||
terminal.write("telnet: TCP disabled\n")
|
||||
return
|
||||
end
|
||||
|
||||
local arg = {...}
|
||||
local host = arg[1]
|
||||
local port = tonumber(arg[2])
|
||||
|
||||
local sock = internet.connect(host, port)
|
||||
|
||||
local connected = false
|
||||
local err
|
||||
for _ = 1, 5 do
|
||||
local ok
|
||||
ok, err = sock.finishConnect()
|
||||
if ok then
|
||||
connected = true
|
||||
break
|
||||
end
|
||||
coroutine.yield()
|
||||
end
|
||||
if not connected then
|
||||
print("telnet: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
print(("connected to %s:%d"):format(host, port))
|
||||
|
||||
while true do
|
||||
local fromSocket = sock.read(math.maxinteger or math.huge)
|
||||
if fromSocket == nil then
|
||||
print("telnet: connection closed")
|
||||
sock.close()
|
||||
return
|
||||
end
|
||||
terminal.write(fromSocket)
|
||||
terminal.flush()
|
||||
local fromTerminal = terminal.read()
|
||||
if fromTerminal == "" then
|
||||
sock.close()
|
||||
return
|
||||
end
|
||||
while fromTerminal ~= "" do
|
||||
local nbytes, err = sock.write(fromTerminal .. "\r\n")
|
||||
if err then
|
||||
print("telnet: " .. err)
|
||||
return
|
||||
end
|
||||
fromTerminal = fromTerminal:sub(nbytes + 1)
|
||||
end
|
||||
end
|
||||
@@ -21,4 +21,4 @@
|
||||
"7": "0xffffff"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -592,7 +592,7 @@ function module.init()
|
||||
local args = { ... }
|
||||
local stringArgs = {}
|
||||
for _, arg in pairs(args) do
|
||||
if type(arg) == "table" then
|
||||
if type(arg)=="table" then
|
||||
table.insert(stringArgs, serialize(arg))
|
||||
elseif tostring(arg) then
|
||||
table.insert(stringArgs, tostring(arg))
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user