Mercurial > emacs
annotate lisp/net-utils.el @ 23264:359e6eb97e11
(printer-name): Fix customize type.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Fri, 18 Sep 1998 09:10:57 +0000 |
parents | 205f3fab9564 |
children | 16780f249ece |
rev | line source |
---|---|
22537 | 1 ;;; net-utils.el --- Network functions |
2 | |
3 ;; Author: Peter Breton <pbreton@cs.umb.edu> | |
4 ;; Created: Sun Mar 16 1997 | |
5 ;; Keywords: network communications | |
6 ;; Time-stamp: <1998-06-13 06:19:01 pbreton> | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 ;; | |
27 ;; There are three main areas of functionality: | |
28 ;; | |
29 ;; * Wrap common network utility programs (ping, traceroute, netstat, | |
30 ;; nslookup, arp, route). Note that these wrappers are of the diagnostic | |
31 ;; functions of these programs only. | |
32 ;; | |
33 ;; * Implement some very basic protocols in Emacs Lisp (finger and whois) | |
34 ;; | |
35 ;; * Support connections to HOST/PORT, generally for debugging and the like. | |
36 ;; In other words, for doing much the same thing as "telnet HOST PORT", and | |
37 ;; then typing commands. | |
38 ;; | |
39 ;; PATHS | |
40 ;; | |
41 ;; On some systems, some of these programs are not in normal user path, | |
42 ;; but rather in /sbin, /usr/sbin, and so on. | |
43 | |
44 | |
45 ;;; Code: | |
46 (eval-when-compile | |
47 (require 'comint) | |
48 (require 'ffap)) | |
49 | |
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
51 ;; Customization Variables | |
52 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
53 | |
54 (defgroup net-utils nil | |
55 "Network utility functions." | |
56 :prefix "net-utils-" | |
57 :group 'comm | |
58 :version "20.3" | |
59 ) | |
60 | |
61 (defcustom net-utils-remove-ctl-m | |
62 (member system-type (list 'windows-nt 'msdos)) | |
63 "If non-nil, remove control-Ms from output." | |
64 :group 'net-utils | |
65 :type 'boolean | |
66 ) | |
67 | |
68 (defcustom traceroute-program | |
69 (if (eq system-type 'windows-nt) | |
70 "tracert" | |
71 "traceroute") | |
72 "Program to trace network hops to a destination." | |
73 :group 'net-utils | |
74 :type 'string | |
75 ) | |
76 | |
77 (defcustom traceroute-program-options nil | |
78 "Options for the traceroute program." | |
79 :group 'net-utils | |
80 :type '(repeat 'string) | |
81 ) | |
82 | |
83 (defcustom ping-program "ping" | |
84 "Program to send network test packets to a host." | |
85 :group 'net-utils | |
86 :type 'string | |
87 ) | |
88 | |
89 ;; On Linux and Irix, the system's ping program seems to send packets | |
90 ;; indefinitely unless told otherwise | |
91 (defcustom ping-program-options | |
92 (and (memq system-type (list 'linux 'gnu/linux 'irix)) | |
93 (list "-c" "4")) | |
94 "Options for the ping program. | |
95 These options can be used to limit how many ICMP packets are emitted." | |
96 :group 'net-utils | |
97 :type '(repeat 'string) | |
98 ) | |
99 | |
100 (defcustom ipconfig-program | |
101 (if (eq system-type 'windows-nt) | |
102 "ipconfig" | |
103 "ifconfig") | |
104 "Program to print network configuration information." | |
105 :group 'net-utils | |
106 :type 'string | |
107 ) | |
108 | |
109 (defcustom ipconfig-program-options | |
110 (list | |
111 (if (eq system-type 'windows-nt) | |
112 "/all" "-a")) | |
113 "Options for ipconfig-program." | |
114 :group 'net-utils | |
115 :type '(repeat 'string) | |
116 ) | |
117 | |
118 (defcustom netstat-program "netstat" | |
119 "Program to print network statistics." | |
120 :group 'net-utils | |
121 :type 'string | |
122 ) | |
123 | |
23187
205f3fab9564
(netstat-program-options): Changed from nil to "-a"
Karl Heuer <kwzh@gnu.org>
parents:
22537
diff
changeset
|
124 (defcustom netstat-program-options |
205f3fab9564
(netstat-program-options): Changed from nil to "-a"
Karl Heuer <kwzh@gnu.org>
parents:
22537
diff
changeset
|
125 (list "-a") |
22537 | 126 "Options for netstat-program." |
127 :group 'net-utils | |
128 :type '(repeat 'string) | |
129 ) | |
130 | |
131 (defcustom arp-program "arp" | |
132 "Program to print IP to address translation tables." | |
133 :group 'net-utils | |
134 :type 'string | |
135 ) | |
136 | |
137 (defcustom arp-program-options | |
138 (list "-a") | |
139 "Options for arp-program." | |
140 :group 'net-utils | |
141 :type '(repeat 'string) | |
142 ) | |
143 | |
144 (defcustom route-program | |
145 (if (eq system-type 'windows-nt) | |
146 "route" | |
147 "netstat") | |
148 "Program to print routing tables." | |
149 :group 'net-utils | |
150 :type 'string | |
151 ) | |
152 | |
153 (defcustom route-program-options | |
154 (if (eq system-type 'windows-nt) | |
155 (list "print") | |
156 (list "-r")) | |
157 "Options for route-program." | |
158 :group 'net-utils | |
159 :type '(repeat 'string) | |
160 ) | |
161 | |
162 (defcustom nslookup-program "nslookup" | |
163 "Program to interactively query DNS information." | |
164 :group 'net-utils | |
165 :type 'string | |
166 ) | |
167 | |
168 (defcustom nslookup-program-options nil | |
169 "List of options to pass to the nslookup program." | |
170 :group 'net-utils | |
171 :type '(repeat 'string) | |
172 ) | |
173 | |
174 (defcustom nslookup-prompt-regexp "^> " | |
175 "Regexp to match the nslookup prompt." | |
176 :group 'net-utils | |
177 :type 'regexp | |
178 ) | |
179 | |
180 (defcustom ftp-program "ftp" | |
181 "Progam to run to do FTP transfers." | |
182 :group 'net-utils | |
183 :type 'string | |
184 ) | |
185 | |
186 (defcustom ftp-program-options nil | |
187 "List of options to pass to the FTP program." | |
188 :group 'net-utils | |
189 :type '(repeat 'string) | |
190 ) | |
191 | |
192 (defcustom ftp-prompt-regexp "^ftp>" | |
193 "Regexp which matches the FTP program's prompt." | |
194 :group 'net-utils | |
195 :type 'regexp | |
196 ) | |
197 | |
198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
199 ;; Nslookup goodies | |
200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
201 | |
202 (defconst nslookup-font-lock-keywords | |
203 (and window-system | |
204 (progn | |
205 (require 'font-lock) | |
206 (list | |
207 (list nslookup-prompt-regexp 0 font-lock-reference-face) | |
208 (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face) | |
209 (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" | |
210 1 font-lock-keyword-face) | |
211 ;; Dotted quads | |
212 (list | |
213 (mapconcat 'identity | |
214 (make-list 4 "[0-9]+") | |
215 "\\.") | |
216 0 font-lock-variable-name-face) | |
217 ;; Host names | |
218 (list | |
219 (let ((host-expression "[-A-Za-z0-9]+")) | |
220 (concat | |
221 (mapconcat 'identity | |
222 (make-list 2 host-expression) | |
223 "\\.") | |
224 "\\(\\." host-expression "\\)*") | |
225 ) | |
226 0 font-lock-variable-name-face) | |
227 ))) | |
228 "Expressions to font-lock for nslookup.") | |
229 | |
230 (defvar nslookup-abbrev-table (make-abbrev-table) | |
231 "Abbrev table for nslookup.") | |
232 | |
233 (define-abbrev nslookup-abbrev-table "e" "exit") | |
234 (define-abbrev nslookup-abbrev-table "f" "finger") | |
235 (define-abbrev nslookup-abbrev-table "h" "help") | |
236 (define-abbrev nslookup-abbrev-table "lse" "lserver") | |
237 (define-abbrev nslookup-abbrev-table "r" "root") | |
238 (define-abbrev nslookup-abbrev-table "s" "set") | |
239 (define-abbrev nslookup-abbrev-table "se" "server") | |
240 (define-abbrev nslookup-abbrev-table "v" "viewer") | |
241 | |
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
243 ;; FTP goodies | |
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
245 | |
246 (defvar ftp-abbrev-table (make-abbrev-table) | |
247 "Abbrev table for ftp.") | |
248 | |
249 (define-abbrev ftp-abbrev-table "q" "quit") | |
250 (define-abbrev ftp-abbrev-table "g" "get") | |
251 (define-abbrev ftp-abbrev-table "p" "prompt") | |
252 (define-abbrev ftp-abbrev-table "anon" "anonymous") | |
253 | |
254 (defconst ftp-font-lock-keywords | |
255 (and window-system | |
256 (progn | |
257 (require 'font-lock) | |
258 (list | |
259 (list ftp-prompt-regexp 0 font-lock-reference-face))))) | |
260 | |
261 | |
262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
263 ;; Utility functions | |
264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
265 | |
266 (defun net-utils-remove-ctrl-m-filter (process output-string) | |
267 "Remove trailing control Ms." | |
268 (let ((old-buffer (current-buffer)) | |
269 (filtered-string output-string)) | |
270 (unwind-protect | |
271 (let ((moving)) | |
272 (set-buffer (process-buffer process)) | |
273 (setq moving (= (point) (process-mark process))) | |
274 | |
275 (while (string-match "\r" filtered-string) | |
276 (setq filtered-string | |
277 (replace-match "" nil nil filtered-string))) | |
278 | |
279 (save-excursion | |
280 ;; Insert the text, moving the process-marker. | |
281 (goto-char (process-mark process)) | |
282 (insert filtered-string) | |
283 (set-marker (process-mark process) (point))) | |
284 (if moving (goto-char (process-mark process)))) | |
285 (set-buffer old-buffer)))) | |
286 | |
287 (defmacro net-utils-run-program (name header program &rest args) | |
288 "Run a network information program." | |
289 (` | |
290 (let ((buf (get-buffer-create (concat "*" (, name) "*")))) | |
291 (set-buffer buf) | |
292 (erase-buffer) | |
293 (insert (, header) "\n") | |
294 (set-process-filter | |
295 (apply 'start-process (, name) buf (, program) (,@ args)) | |
296 'net-utils-remove-ctrl-m-filter) | |
297 (display-buffer buf)))) | |
298 | |
299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
300 ;; Wrappers for external network programs | |
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
302 | |
303 ;;;###autoload | |
304 (defun traceroute (target) | |
305 "Run traceroute program for TARGET." | |
306 (interactive "sTarget: ") | |
307 (let ((options | |
308 (if traceroute-program-options | |
309 (append traceroute-program-options (list target)) | |
310 (list target)))) | |
311 (net-utils-run-program | |
312 (concat "Traceroute" " " target) | |
313 (concat "** Traceroute ** " traceroute-program " ** " target) | |
314 traceroute-program | |
315 options | |
316 ))) | |
317 | |
318 ;;;###autoload | |
319 (defun ping (host) | |
320 "Ping HOST. | |
321 If your system's ping continues until interrupted, you can try setting | |
322 `ping-program-options'." | |
323 (interactive | |
324 (list | |
325 (progn | |
326 (require 'ffap) | |
327 (read-from-minibuffer | |
328 "Ping host: " | |
329 (or (ffap-string-at-point 'machine) ""))))) | |
330 (let ((options | |
331 (if ping-program-options | |
332 (append ping-program-options (list host)) | |
333 (list host)))) | |
334 (net-utils-run-program | |
335 (concat "Ping" " " host) | |
336 (concat "** Ping ** " ping-program " ** " host) | |
337 ping-program | |
338 options | |
339 ))) | |
340 | |
341 ;;;###autoload | |
342 (defun ipconfig () | |
343 "Run ipconfig program." | |
344 (interactive) | |
345 (net-utils-run-program | |
346 "Ipconfig" | |
347 (concat "** Ipconfig ** " ipconfig-program " ** ") | |
348 ipconfig-program | |
349 ipconfig-program-options | |
350 )) | |
351 | |
352 ;; This is the normal name on most Unixes. | |
353 ;;;###autoload | |
354 (defalias 'ifconfig 'ipconfig) | |
355 | |
356 ;;;###autoload | |
357 (defun netstat () | |
358 "Run netstat program." | |
359 (interactive) | |
360 (net-utils-run-program | |
361 "Netstat" | |
362 (concat "** Netstat ** " netstat-program " ** ") | |
363 netstat-program | |
364 netstat-program-options | |
365 )) | |
366 | |
367 ;;;###autoload | |
368 (defun arp () | |
369 "Run the arp program." | |
370 (interactive) | |
371 (net-utils-run-program | |
372 "Arp" | |
373 (concat "** Arp ** " arp-program " ** ") | |
374 arp-program | |
375 arp-program-options | |
376 )) | |
377 | |
378 ;;;###autoload | |
379 (defun route () | |
380 "Run the route program." | |
381 (interactive) | |
382 (net-utils-run-program | |
383 "Route" | |
384 (concat "** Route ** " route-program " ** ") | |
385 route-program | |
386 route-program-options | |
387 )) | |
388 | |
389 ;; FIXME -- Needs to be a process filter | |
390 ;; (defun netstat-with-filter (filter) | |
391 ;; "Run netstat program." | |
392 ;; (interactive "sFilter: ") | |
393 ;; (netstat) | |
394 ;; (set-buffer (get-buffer "*Netstat*")) | |
395 ;; (goto-char (point-min)) | |
396 ;; (delete-matching-lines filter) | |
397 ;; ) | |
398 | |
399 ;;;###autoload | |
400 (defun nslookup-host (host) | |
401 "Lookup the DNS information for HOST." | |
402 (interactive | |
403 (list | |
404 (read-from-minibuffer | |
405 "Lookup host: " | |
406 (or (ffap-string-at-point 'machine) "")))) | |
407 (let ((options | |
408 (if nslookup-program-options | |
409 (append nslookup-program-options (list host)) | |
410 (list host)))) | |
411 (net-utils-run-program | |
412 "Nslookup" | |
413 (concat "** " | |
414 (mapconcat 'identity | |
415 (list "Nslookup" host nslookup-program) | |
416 " ** ")) | |
417 nslookup-program | |
418 options | |
419 ))) | |
420 | |
421 | |
422 ;;;###autoload | |
423 (defun nslookup () | |
424 "Run nslookup program." | |
425 (interactive) | |
426 (comint-run nslookup-program) | |
427 (set-process-filter (get-buffer-process "*nslookup*") | |
428 'net-utils-remove-ctrl-m-filter) | |
429 (set | |
430 (make-local-variable 'font-lock-defaults) | |
431 '((nslookup-font-lock-keywords))) | |
432 (set | |
433 (make-local-variable 'local-abbrev-table) | |
434 nslookup-abbrev-table) | |
435 (abbrev-mode t) | |
436 (make-local-variable 'comint-prompt-regexp) | |
437 (setq comint-prompt-regexp nslookup-prompt-regexp) | |
438 ) | |
439 | |
440 ;; This is a lot less than ange-ftp, but much simpler. | |
441 ;;;###autoload | |
442 (defun ftp (host) | |
443 "Run ftp program." | |
444 (interactive "sFtp to Host: ") | |
445 (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) | |
446 (set-buffer buf) | |
447 (comint-mode) | |
448 (comint-exec buf (concat "ftp-" host) ftp-program nil | |
449 (if ftp-program-options | |
450 (append (list host) ftp-program-options) | |
451 (list host))) | |
452 (set | |
453 (make-local-variable 'font-lock-defaults) | |
454 '((ftp-font-lock-keywords))) | |
455 | |
456 (make-local-variable 'comint-prompt-regexp) | |
457 (setq comint-prompt-regexp ftp-prompt-regexp) | |
458 | |
459 ;; Already buffer local! | |
460 (setq comint-output-filter-functions | |
461 (list 'comint-watch-for-password-prompt)) | |
462 (set | |
463 (make-local-variable 'local-abbrev-table) | |
464 ftp-abbrev-table) | |
465 (abbrev-mode t) | |
466 (switch-to-buffer-other-window buf) | |
467 )) | |
468 | |
469 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
470 ;; Network Connections | |
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
472 | |
473 ;; Full list is available at: | |
474 ;; ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers | |
475 (defvar network-connection-service-alist | |
476 (list | |
477 (cons 'echo 7) | |
478 (cons 'active-users 11) | |
479 (cons 'daytime 13) | |
480 (cons 'chargen 19) | |
481 (cons 'ftp 21) | |
482 (cons 'telnet 23) | |
483 (cons 'smtp 25) | |
484 (cons 'time 37) | |
485 (cons 'whois 43) | |
486 (cons 'gopher 70) | |
487 (cons 'finger 79) | |
488 (cons 'www 80) | |
489 (cons 'pop2 109) | |
490 (cons 'pop3 110) | |
491 (cons 'sun-rpc 111) | |
492 (cons 'nntp 119) | |
493 (cons 'ntp 123) | |
494 (cons 'netbios-name 137) | |
495 (cons 'netbios-data 139) | |
496 (cons 'irc 194) | |
497 (cons 'https 443) | |
498 (cons 'rlogin 513) | |
499 ) | |
500 "Alist of services and associated TCP port numbers. | |
501 This list in not complete.") | |
502 | |
503 ;; Workhorse macro | |
504 (defmacro run-network-program (process-name host port | |
505 &optional initial-string) | |
506 (` | |
507 (let ((tcp-connection) | |
508 (buf) | |
509 ) | |
510 (setq buf (get-buffer-create (concat "*" (, process-name) "*"))) | |
511 (set-buffer buf) | |
512 (or | |
513 (setq tcp-connection | |
514 (open-network-stream | |
515 (, process-name) | |
516 buf | |
517 (, host) | |
518 (, port) | |
519 )) | |
520 (error "Could not open connection to %s" (, host))) | |
521 (erase-buffer) | |
522 (set-marker (process-mark tcp-connection) (point-min)) | |
523 (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter) | |
524 (and (, initial-string) | |
525 (process-send-string tcp-connection | |
526 (concat (, initial-string) "\r\n"))) | |
527 (display-buffer buf)))) | |
528 | |
529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
530 ;; Simple protocols | |
531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
532 | |
533 ;; Finger protocol | |
534 ;;;###autoload | |
535 (defun finger (user host) | |
536 "Finger USER on HOST." | |
537 ;; One of those great interactive statements that's actually | |
538 ;; longer than the function call! The idea is that if the user | |
539 ;; uses a string like "pbreton@cs.umb.edu", we won't ask for the | |
540 ;; host name. If we don't see an "@", we'll prompt for the host. | |
541 (interactive | |
542 (progn | |
543 (require 'ffap) | |
544 (let* ((answer (read-from-minibuffer "Finger User: " | |
545 (ffap-string-at-point 'url))) | |
546 (index (string-match (regexp-quote "@") answer)) | |
547 ) | |
548 (if index | |
549 (list | |
550 (substring answer 0 index) | |
551 (substring answer (1+ index))) | |
552 (list | |
553 answer | |
554 (read-from-minibuffer | |
555 "At Host: " | |
556 (or (ffap-string-at-point 'machine) ""))))))) | |
557 (let* ( | |
558 (user-and-host (concat user "@" host)) | |
559 (process-name | |
560 (concat "Finger [" user-and-host "]")) | |
561 ) | |
562 (run-network-program | |
563 process-name | |
564 host | |
565 (cdr (assoc 'finger network-connection-service-alist)) | |
566 user-and-host | |
567 ))) | |
568 | |
569 (defcustom whois-server-name "whois.internic.net" | |
570 "Host name for the whois service." | |
571 :group 'net-utils | |
572 :type 'string | |
573 ) | |
574 | |
575 ;; Whois protocol | |
576 ;;;###autoload | |
577 (defun whois (arg search-string) | |
578 "Send SEARCH-STRING to server defined by the `whois-server-name' variable. | |
579 With argument, prompt for whois server." | |
580 (interactive "P\nsWhois: ") | |
581 (let ((host | |
582 (if arg | |
583 (read-from-minibuffer "Whois server name: ") | |
584 whois-server-name)) | |
585 ) | |
586 (run-network-program | |
587 "Whois" | |
588 host | |
589 (cdr (assoc 'whois network-connection-service-alist)) | |
590 search-string | |
591 ))) | |
592 | |
593 (defcustom whois-reverse-lookup-server "whois.arin.net" | |
594 "Server which provides inverse DNS mapping." | |
595 :group 'net-utils | |
596 :type 'string | |
597 ) | |
598 | |
599 ;;;###autoload | |
600 (defun whois-reverse-lookup () | |
601 (interactive) | |
602 (let ((whois-server-name whois-reverse-lookup-server)) | |
603 (call-interactively 'whois))) | |
604 | |
605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
606 ;;; General Network connection | |
607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
608 | |
609 ;;;###autoload | |
610 (defun network-connection-to-service (host service) | |
611 "Open a network connection to SERVICE on HOST." | |
612 (interactive | |
613 (list | |
614 (progn | |
615 (require 'ffap) | |
616 (read-from-minibuffer "Host: " | |
617 (ffap-string-at-point 'machine))) | |
618 (completing-read "Service: " | |
619 (mapcar | |
620 (function | |
621 (lambda (elt) | |
622 (list (symbol-name (car elt))))) | |
623 network-connection-service-alist)))) | |
624 (network-connection | |
625 host | |
626 (cdr (assoc (intern service) network-connection-service-alist))) | |
627 ) | |
628 | |
629 ;;;###autoload | |
630 (defun network-connection (host port) | |
631 "Open a network connection to HOST on PORT." | |
632 (interactive "sHost: \nnPort: ") | |
633 (network-service-connection host (number-to-string port))) | |
634 | |
635 (defun network-service-connection (host service) | |
636 "Open a network connection to SERVICE on HOST." | |
637 (let ( | |
638 (process-name (concat "Network Connection [" host " " service "]")) | |
639 (portnum (string-to-number service)) | |
640 ) | |
641 (or (zerop portnum) (setq service portnum)) | |
642 (make-comint | |
643 process-name | |
644 (cons host service)) | |
645 (pop-to-buffer (get-buffer (concat "*" process-name "*"))) | |
646 )) | |
647 | |
648 (provide 'net-utils) | |
649 | |
650 ;;; net-utils.el ends here |