Function: telnet
telnet is an autoloaded, interactive and byte-compiled function
defined in telnet.el.gz.
Signature
(telnet HOST &optional PORT)
Documentation
Open a network login connection to host named HOST (a string).
Optional arg PORT specifies alternative port to connect to.
Interactively, use C-u (universal-argument) prefix to be prompted for port number.
Communication with HOST is recorded in a buffer *PROGRAM-HOST*
where PROGRAM is the telnet program being used. This program
is controlled by the contents of the global variable telnet-host-properties,
falling back on the value of the global variable telnet-program.
Normally input is edited in Emacs and sent a line at a time.
Probably introduced at or before Emacs version 22.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/net/telnet.el.gz
;;;###autoload
(defun telnet (host &optional port)
"Open a network login connection to host named HOST (a string).
Optional arg PORT specifies alternative port to connect to.
Interactively, use \\[universal-argument] prefix to be prompted for port number.
Communication with HOST is recorded in a buffer `*PROGRAM-HOST*'
where PROGRAM is the telnet program being used. This program
is controlled by the contents of the global variable `telnet-host-properties',
falling back on the value of the global variable `telnet-program'.
Normally input is edited in Emacs and sent a line at a time."
(interactive (list (read-string "Open connection to host: ")
(cond
((null current-prefix-arg) nil)
((consp current-prefix-arg) (read-string "Port: "))
(t (prefix-numeric-value current-prefix-arg)))))
(if (and port (numberp port))
(setq port (int-to-string port)))
(let* ((comint-delimiter-argument-list '(?\ ?\t))
(properties (cdr (assoc host telnet-host-properties)))
(telnet-program (if properties (car properties) telnet-program))
(hname (if port (concat host ":" port) host))
(name (concat telnet-program "-" (comint-arguments hname 0 nil) ))
(buffer (get-buffer (concat "*" name "*")))
(telnet-options (if (cdr properties) (cons "-l" (cdr properties))))
process)
(if (and buffer (get-buffer-process buffer))
(switch-to-buffer (concat "*" name "*"))
(switch-to-buffer
(apply #'make-comint name telnet-program nil telnet-options))
(setq process (get-buffer-process (current-buffer)))
(set-process-filter process #'telnet-initial-filter)
;; Don't send the `open' cmd till telnet is ready for it.
(accept-process-output process)
(erase-buffer)
(process-send-string process (concat "open " host
(if port " " "") (or port "")
"\n"))
(telnet-mode)
(setq-local telnet-connect-command (list 'telnet host port))
(setq comint-input-sender 'telnet-simple-send)
(setq telnet-count telnet-initial-count))))