홈페이지 : http://tmartin.org/tcltelnet/
이 확장 패키지는 Tcl 클라이언트를 구현한 순수 Tcl 패키지입니다. 텔넷 인터페이스를 자동화해야 할 필요가 있어서 이 패키지를 작성했습니다. 과거에는 저를 포함한 많은 사람들이 이 작업을 위해 Expect를 사용하곤 했습니다. 물론 Expect도 잘 작동하지만, 항상 이식성이 뛰어난 것은 아니었고(특히 Windows 환경에서) 애플리케이션에 또 다른 외부 의존성을 추가하게 되었습니다.
tclTelnet은 BSD 라이선스 하에 배포됩니다.
This is a pure Tcl package that implements a Tcl client. I wrote this because I needed to automate a telnet interface. In the past, I and others would use Expect for this task. While this worked, it was not always portable (especially to Windows) and it added another external dependancy to the application.
tclTelnet is licenced under the BSD license.
#!/usr/bin/tclsh
# Copyright (c) 2000 by Todd J Martin <todd.martin@acm.org>
# $Id: telnet_test.tcl,v 1.14 2005/02/05 02:41:46 todd Exp $
#
# This file is used to for testing the telnet library. It can also serve as
# an example of how to use the library. The file implements a very simple
# telnet client in pure tcl.
lappend auto_path [pwd]
package require telnet
if { $argc != 2 } {
puts "Wrong number of args"
puts "Usage: telnet_test.tcl host port"
exit 1
}
set host [lindex $argv 0]
set port [lindex $argv 1]
set ttyBuffer {}
proc readTty {tty} {
if {[catch {set input [read $tty]} err]} {
error $err $::errorInfo
}
append ::ttyBuffer $input
set ::telnetEvent readTty
}
proc readStdin {} {
if {[eof stdin]} {
set ::telnetEvent EOF
return
}
if {[catch {set input [gets stdin]} err]} {
error $err $::errorInfo
}
# Add a carriage return because if you are interactive on windows, then
# the carriage return is eaten by the console
append ::ttyBuffer $input "\r"
set ::telnetEvent readStdin
}
proc tcpRead {pt} {
if {[eof $pt]} {
set ::telnetEvent EOF
return
}
append ::telnetBuffer [telnet::read $pt]
set ::telnetEvent tcpRead
}
set pt [telnet::open $host $port]
fconfigure $pt -blocking false -buffering none
fileevent $pt readable [list tcpRead $pt]
if {[string match $tcl_platform(platform) "unix"]} {
close stdin
set tty [open /dev/tty r]
exec stty icanon brkint min 1 time 0 -istrip -ixon -ixoff -icanon -echo < /dev/tty
fconfigure $tty -blocking false -buffering none
fileevent $tty readable [list readTty $tty]
} else {
fileevent stdin readable [list readStdin]
}
fconfigure stdout -buffering none
while {1} {
set telnetEvent {}
vwait telnetEvent
if {[string equal $telnetEvent "tcpRead"]} {
puts -nonewline "$telnetBuffer"
set telnetBuffer {}
} elseif {[string equal $telnetEvent "readTty"] || \
[string equal $telnetEvent "readStdin"] } {
if {[catch {telnet::write $pt $ttyBuffer} err]} {
# Must be shutting down the connection
break
}
set ttyBuffer {}
} elseif {[string equal $telnetEvent "EOF"]} {
break
}
}
close $pt
'Tcl & Tk > 확장 패키지 (Extension Package)' 카테고리의 다른 글
hash 0.2a1 (0) | 2025.09.01 |
---|---|
tclpcap 2.0.0 (0) | 2025.09.01 |
TODL 0.1 (0) | 2025.09.01 |
Sugar 0.1 (0) | 2025.08.27 |
yajl-tcl 1.8.1 (0) | 2025.08.27 |