| 1 |
############################################################################ |
| 2 |
# |
| 3 |
# File: tnet.icn |
| 4 |
# |
| 5 |
# Subject: Program to talk to telnet port |
| 6 |
# |
| 7 |
# Author: Gregg M. Townsend |
| 8 |
# |
| 9 |
# Date: August 4, 2000 |
| 10 |
# |
| 11 |
############################################################################ |
| 12 |
# |
| 13 |
# Usage: tnet hostname portnumber |
| 14 |
# |
| 15 |
# This is a VERY simple telnet client. It connects to a remote port |
| 16 |
# and exchanges data between the port and the terminal. The port is |
| 17 |
# read and echoed to the terminal until the port is quiet for 200 msec; |
| 18 |
# then one line from the terminal is sent to the port. This process |
| 19 |
# repeats until an EOF is read from either source. |
| 20 |
# |
| 21 |
# Some interesting port numbers can usually be found in /etc/services. |
| 22 |
# For example, network news is read from a news server using port 119. |
| 23 |
# |
| 24 |
# This program does not work under Irix because poll(2) always returns 1. |
| 25 |
# |
| 26 |
############################################################################ |
| 27 |
|
| 28 |
link cfunc # link standard C functions transparently |
| 29 |
|
| 30 |
procedure main(args) |
| 31 |
local h, p, f, s |
| 32 |
|
| 33 |
h := args[1] | &host # default is current host |
| 34 |
p := integer(args[2]) | 13 # default is port 13 (time of day) |
| 35 |
|
| 36 |
f := tconnect(h, p) | stop("can't connect to port ", p, " of ", h) |
| 37 |
|
| 38 |
fpoll(f, 2000) # wait up to 2 sec for initial response |
| 39 |
repeat { |
| 40 |
while fpoll(f, 200) do # read characters from port until timeout |
| 41 |
writes(reads(f)) | { write("EOF"); break break } |
| 42 |
writes("\n> ") # issue prompt |
| 43 |
s := read() | break # read line from terminal |
| 44 |
seek(f) # enable switch from input to output |
| 45 |
flush(f) # workaround for Dec Alpha bug |
| 46 |
write(f, s) # write terminal input to port |
| 47 |
seek(f) # enable switch from output to input |
| 48 |
} |
| 49 |
end |