Mercurial > emacs
annotate lisp/net/net-utils.el @ 29637:6b63e5410a0e
*** empty log message ***
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 13 Jun 2000 23:51:46 +0000 |
parents | a3541330de52 |
children | 716c9bd98063 |
rev | line source |
---|---|
28210 | 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: <1999-11-13 10: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 | |
49 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
50 ;; Customization Variables | |
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
52 | |
53 (defgroup net-utils nil | |
54 "Network utility functions." | |
55 :prefix "net-utils-" | |
56 :group 'comm | |
57 :version "20.3" | |
58 ) | |
59 | |
60 (defcustom net-utils-remove-ctl-m | |
61 (member system-type (list 'windows-nt 'msdos)) | |
62 "If non-nil, remove control-Ms from output." | |
63 :group 'net-utils | |
64 :type 'boolean | |
65 ) | |
66 | |
67 (defcustom traceroute-program | |
68 (if (eq system-type 'windows-nt) | |
69 "tracert" | |
70 "traceroute") | |
71 "Program to trace network hops to a destination." | |
72 :group 'net-utils | |
73 :type 'string | |
74 ) | |
75 | |
76 (defcustom traceroute-program-options nil | |
77 "Options for the traceroute program." | |
78 :group 'net-utils | |
79 :type '(repeat string) | |
80 ) | |
81 | |
82 (defcustom ping-program "ping" | |
83 "Program to send network test packets to a host." | |
84 :group 'net-utils | |
85 :type 'string | |
86 ) | |
87 | |
88 ;; On Linux and Irix, the system's ping program seems to send packets | |
89 ;; indefinitely unless told otherwise | |
90 (defcustom ping-program-options | |
91 (and (memq system-type (list 'linux 'gnu/linux 'irix)) | |
92 (list "-c" "4")) | |
93 "Options for the ping program. | |
94 These options can be used to limit how many ICMP packets are emitted." | |
95 :group 'net-utils | |
96 :type '(repeat string) | |
97 ) | |
98 | |
99 (defcustom ipconfig-program | |
100 (if (eq system-type 'windows-nt) | |
101 "ipconfig" | |
102 "ifconfig") | |
103 "Program to print network configuration information." | |
104 :group 'net-utils | |
105 :type 'string | |
106 ) | |
107 | |
108 (defcustom ipconfig-program-options | |
109 (list | |
110 (if (eq system-type 'windows-nt) | |
111 "/all" "-a")) | |
112 "Options for ipconfig-program." | |
113 :group 'net-utils | |
114 :type '(repeat string) | |
115 ) | |
116 | |
117 (defcustom netstat-program "netstat" | |
118 "Program to print network statistics." | |
119 :group 'net-utils | |
120 :type 'string | |
121 ) | |
122 | |
123 (defcustom netstat-program-options | |
124 (list "-a") | |
125 "Options for netstat-program." | |
126 :group 'net-utils | |
127 :type '(repeat string) | |
128 ) | |
129 | |
130 (defcustom arp-program "arp" | |
131 "Program to print IP to address translation tables." | |
132 :group 'net-utils | |
133 :type 'string | |
134 ) | |
135 | |
136 (defcustom arp-program-options | |
137 (list "-a") | |
138 "Options for arp-program." | |
139 :group 'net-utils | |
140 :type '(repeat string) | |
141 ) | |
142 | |
143 (defcustom route-program | |
144 (if (eq system-type 'windows-nt) | |
145 "route" | |
146 "netstat") | |
147 "Program to print routing tables." | |
148 :group 'net-utils | |
149 :type 'string | |
150 ) | |
151 | |
152 (defcustom route-program-options | |
153 (if (eq system-type 'windows-nt) | |
154 (list "print") | |
155 (list "-r")) | |
156 "Options for route-program." | |
157 :group 'net-utils | |
158 :type '(repeat string) | |
159 ) | |
160 | |
161 (defcustom nslookup-program "nslookup" | |
162 "Program to interactively query DNS information." | |
163 :group 'net-utils | |
164 :type 'string | |
165 ) | |
166 | |
167 (defcustom nslookup-program-options nil | |
168 "List of options to pass to the nslookup program." | |
169 :group 'net-utils | |
170 :type '(repeat string) | |
171 ) | |
172 | |
173 (defcustom nslookup-prompt-regexp "^> " | |
174 "Regexp to match the nslookup prompt." | |
175 :group 'net-utils | |
176 :type 'regexp | |
177 ) | |
178 | |
179 (defcustom dig-program "dig" | |
180 "Program to query DNS information." | |
181 :group 'net-utils | |
182 :type 'string | |
183 ) | |
184 | |
185 (defcustom ftp-program "ftp" | |
186 "Progam to run to do FTP transfers." | |
187 :group 'net-utils | |
188 :type 'string | |
189 ) | |
190 | |
191 (defcustom ftp-program-options nil | |
192 "List of options to pass to the FTP program." | |
193 :group 'net-utils | |
194 :type '(repeat string) | |
195 ) | |
196 | |
197 (defcustom ftp-prompt-regexp "^ftp>" | |
198 "Regexp which matches the FTP program's prompt." | |
199 :group 'net-utils | |
200 :type 'regexp | |
201 ) | |
202 | |
203 (defcustom smbclient-program "smbclient" | |
204 "Smbclient program." | |
205 :group 'net-utils | |
206 :type 'string | |
207 ) | |
208 | |
209 (defcustom smbclient-program-options nil | |
210 "List of options to pass to the smbclient program." | |
211 :group 'net-utils | |
212 :type '(repeat string) | |
213 ) | |
214 | |
215 (defcustom smbclient-prompt-regexp "^smb: \>" | |
216 "Regexp which matches the smbclient program's prompt." | |
217 :group 'net-utils | |
218 :type 'regexp | |
219 ) | |
220 | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
221 ;; Internal variables |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
222 (defvar network-connection-service nil) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
223 (defvar network-connection-host nil) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
224 |
28210 | 225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
226 ;; Nslookup goodies | |
227 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
228 | |
229 (defconst nslookup-font-lock-keywords | |
230 (and window-system | |
231 (progn | |
232 (require 'font-lock) | |
233 (list | |
234 (list nslookup-prompt-regexp 0 font-lock-reference-face) | |
235 (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face) | |
236 (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" | |
237 1 font-lock-keyword-face) | |
238 ;; Dotted quads | |
239 (list | |
240 (mapconcat 'identity | |
241 (make-list 4 "[0-9]+") | |
242 "\\.") | |
243 0 font-lock-variable-name-face) | |
244 ;; Host names | |
245 (list | |
246 (let ((host-expression "[-A-Za-z0-9]+")) | |
247 (concat | |
248 (mapconcat 'identity | |
249 (make-list 2 host-expression) | |
250 "\\.") | |
251 "\\(\\." host-expression "\\)*") | |
252 ) | |
253 0 font-lock-variable-name-face) | |
254 ))) | |
255 "Expressions to font-lock for nslookup.") | |
256 | |
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
258 ;; FTP goodies | |
259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
260 | |
261 (defconst ftp-font-lock-keywords | |
262 (and window-system | |
263 (progn | |
264 (require 'font-lock) | |
265 (list | |
266 (list ftp-prompt-regexp 0 font-lock-reference-face))))) | |
267 | |
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
269 ;; smbclient goodies | |
270 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
271 | |
272 (defconst smbclient-font-lock-keywords | |
273 (and window-system | |
274 (progn | |
275 (require 'font-lock) | |
276 (list | |
277 (list smbclient-prompt-regexp 0 font-lock-reference-face))))) | |
278 | |
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
280 ;; Utility functions | |
281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
282 | |
283 ;; Simplified versions of some at-point functions from ffap.el. | |
284 ;; It's not worth loading all of ffap just for these. | |
285 (defun net-utils-machine-at-point () | |
286 (let ((pt (point))) | |
287 (buffer-substring-no-properties | |
288 (save-excursion | |
289 (skip-chars-backward "-a-zA-Z0-9.") | |
290 (point)) | |
291 (save-excursion | |
292 (skip-chars-forward "-a-zA-Z0-9.") | |
293 (skip-chars-backward "." pt) | |
294 (point))))) | |
295 | |
296 (defun net-utils-url-at-point () | |
297 (let ((pt (point))) | |
298 (buffer-substring-no-properties | |
299 (save-excursion | |
300 (skip-chars-backward "--:=&?$+@-Z_a-z~#,%") | |
301 (skip-chars-forward "^A-Za-z0-9" pt) | |
302 (point)) | |
303 (save-excursion | |
304 (skip-chars-forward "--:=&?$+@-Z_a-z~#,%") | |
305 (skip-chars-backward ":;.,!?" pt) | |
306 (point))))) | |
307 | |
308 | |
309 (defun net-utils-remove-ctrl-m-filter (process output-string) | |
310 "Remove trailing control Ms." | |
311 (let ((old-buffer (current-buffer)) | |
312 (filtered-string output-string)) | |
313 (unwind-protect | |
314 (let ((moving)) | |
315 (set-buffer (process-buffer process)) | |
316 (setq moving (= (point) (process-mark process))) | |
317 | |
318 (while (string-match "\r" filtered-string) | |
319 (setq filtered-string | |
320 (replace-match "" nil nil filtered-string))) | |
321 | |
322 (save-excursion | |
323 ;; Insert the text, moving the process-marker. | |
324 (goto-char (process-mark process)) | |
325 (insert filtered-string) | |
326 (set-marker (process-mark process) (point))) | |
327 (if moving (goto-char (process-mark process)))) | |
328 (set-buffer old-buffer)))) | |
329 | |
330 (defmacro net-utils-run-program (name header program &rest args) | |
331 "Run a network information program." | |
332 ` (let ((buf (get-buffer-create (concat "*" ,name "*")))) | |
333 (set-buffer buf) | |
334 (erase-buffer) | |
335 (insert ,header "\n") | |
336 (set-process-filter | |
337 (apply 'start-process ,name buf ,program ,@args) | |
338 'net-utils-remove-ctrl-m-filter) | |
339 (display-buffer buf))) | |
340 | |
341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
342 ;; Wrappers for external network programs | |
343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
344 | |
345 ;;;###autoload | |
346 (defun traceroute (target) | |
347 "Run traceroute program for TARGET." | |
348 (interactive "sTarget: ") | |
349 (let ((options | |
350 (if traceroute-program-options | |
351 (append traceroute-program-options (list target)) | |
352 (list target)))) | |
353 (net-utils-run-program | |
354 (concat "Traceroute" " " target) | |
355 (concat "** Traceroute ** " traceroute-program " ** " target) | |
356 traceroute-program | |
357 options | |
358 ))) | |
359 | |
360 ;;;###autoload | |
361 (defun ping (host) | |
362 "Ping HOST. | |
363 If your system's ping continues until interrupted, you can try setting | |
364 `ping-program-options'." | |
365 (interactive | |
366 (list (read-from-minibuffer "Ping host: " (net-utils-machine-at-point)))) | |
367 (let ((options | |
368 (if ping-program-options | |
369 (append ping-program-options (list host)) | |
370 (list host)))) | |
371 (net-utils-run-program | |
372 (concat "Ping" " " host) | |
373 (concat "** Ping ** " ping-program " ** " host) | |
374 ping-program | |
375 options | |
376 ))) | |
377 | |
378 ;;;###autoload | |
379 (defun ipconfig () | |
380 "Run ipconfig program." | |
381 (interactive) | |
382 (net-utils-run-program | |
383 "Ipconfig" | |
384 (concat "** Ipconfig ** " ipconfig-program " ** ") | |
385 ipconfig-program | |
386 ipconfig-program-options | |
387 )) | |
388 | |
389 ;; This is the normal name on most Unixes. | |
390 ;;;###autoload | |
391 (defalias 'ifconfig 'ipconfig) | |
392 | |
393 ;;;###autoload | |
394 (defun netstat () | |
395 "Run netstat program." | |
396 (interactive) | |
397 (net-utils-run-program | |
398 "Netstat" | |
399 (concat "** Netstat ** " netstat-program " ** ") | |
400 netstat-program | |
401 netstat-program-options | |
402 )) | |
403 | |
404 ;;;###autoload | |
405 (defun arp () | |
406 "Run the arp program." | |
407 (interactive) | |
408 (net-utils-run-program | |
409 "Arp" | |
410 (concat "** Arp ** " arp-program " ** ") | |
411 arp-program | |
412 arp-program-options | |
413 )) | |
414 | |
415 ;;;###autoload | |
416 (defun route () | |
417 "Run the route program." | |
418 (interactive) | |
419 (net-utils-run-program | |
420 "Route" | |
421 (concat "** Route ** " route-program " ** ") | |
422 route-program | |
423 route-program-options | |
424 )) | |
425 | |
426 ;; FIXME -- Needs to be a process filter | |
427 ;; (defun netstat-with-filter (filter) | |
428 ;; "Run netstat program." | |
429 ;; (interactive "sFilter: ") | |
430 ;; (netstat) | |
431 ;; (set-buffer (get-buffer "*Netstat*")) | |
432 ;; (goto-char (point-min)) | |
433 ;; (delete-matching-lines filter) | |
434 ;; ) | |
435 | |
436 ;;;###autoload | |
437 (defun nslookup-host (host) | |
438 "Lookup the DNS information for HOST." | |
439 (interactive | |
440 (list (read-from-minibuffer "Lookup host: " (net-utils-machine-at-point)))) | |
441 (let ((options | |
442 (if nslookup-program-options | |
443 (append nslookup-program-options (list host)) | |
444 (list host)))) | |
445 (net-utils-run-program | |
446 "Nslookup" | |
447 (concat "** " | |
448 (mapconcat 'identity | |
449 (list "Nslookup" host nslookup-program) | |
450 " ** ")) | |
451 nslookup-program | |
452 options | |
453 ))) | |
454 | |
455 | |
456 ;;;###autoload | |
457 (defun nslookup () | |
458 "Run nslookup program." | |
459 (interactive) | |
460 (require 'comint) | |
461 (comint-run nslookup-program) | |
462 (set-process-filter (get-buffer-process "*nslookup*") | |
463 'net-utils-remove-ctrl-m-filter) | |
464 (nslookup-mode) | |
465 ) | |
466 | |
467 ;; Using a derived mode gives us keymaps, hooks, etc. | |
468 (define-derived-mode | |
469 nslookup-mode comint-mode "Nslookup" | |
470 "Major mode for interacting with the nslookup program." | |
471 (set | |
472 (make-local-variable 'font-lock-defaults) | |
473 '((nslookup-font-lock-keywords))) | |
474 (setq local-abbrev-table nslookup-mode-abbrev-table) | |
475 (abbrev-mode t) | |
476 (make-local-variable 'comint-prompt-regexp) | |
477 (setq comint-prompt-regexp nslookup-prompt-regexp) | |
478 (make-local-variable 'comint-input-autoexpand) | |
479 (setq comint-input-autoexpand t) | |
480 ) | |
481 | |
482 (define-key nslookup-mode-map "\t" 'comint-dynamic-complete) | |
483 | |
484 (define-abbrev nslookup-mode-abbrev-table "e" "exit") | |
485 (define-abbrev nslookup-mode-abbrev-table "f" "finger") | |
486 (define-abbrev nslookup-mode-abbrev-table "h" "help") | |
487 (define-abbrev nslookup-mode-abbrev-table "lse" "lserver") | |
488 (define-abbrev nslookup-mode-abbrev-table "q" "exit") | |
489 (define-abbrev nslookup-mode-abbrev-table "r" "root") | |
490 (define-abbrev nslookup-mode-abbrev-table "s" "set") | |
491 (define-abbrev nslookup-mode-abbrev-table "se" "server") | |
492 (define-abbrev nslookup-mode-abbrev-table "v" "viewer") | |
493 | |
494 ;;;###autoload | |
495 (defun dig (host) | |
496 "Run dig program." | |
497 (interactive | |
498 (list | |
499 (progn | |
500 (require 'ffap) | |
501 (read-from-minibuffer | |
502 "Lookup host: " | |
503 (or (ffap-string-at-point 'machine) ""))))) | |
504 (net-utils-run-program | |
505 "Dig" | |
506 (concat "** " | |
507 (mapconcat 'identity | |
508 (list "Dig" host dig-program) | |
509 " ** ")) | |
510 dig-program | |
511 (list host) | |
512 )) | |
513 | |
514 ;; This is a lot less than ange-ftp, but much simpler. | |
515 ;;;###autoload | |
516 (defun ftp (host) | |
517 "Run ftp program." | |
518 (interactive | |
519 (list | |
520 (read-from-minibuffer | |
521 "Ftp to Host: " (net-utils-machine-at-point)))) | |
522 (require 'comint) | |
523 (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) | |
524 (set-buffer buf) | |
525 (comint-mode) | |
526 (comint-exec buf (concat "ftp-" host) ftp-program nil | |
527 (if ftp-program-options | |
528 (append (list host) ftp-program-options) | |
529 (list host))) | |
530 (ftp-mode) | |
531 (switch-to-buffer-other-window buf) | |
532 )) | |
533 | |
534 (define-derived-mode | |
535 ftp-mode comint-mode "FTP" | |
536 "Major mode for interacting with the ftp program." | |
537 | |
538 (set | |
539 (make-local-variable 'font-lock-defaults) | |
540 '((ftp-font-lock-keywords))) | |
541 | |
542 (make-local-variable 'comint-prompt-regexp) | |
543 (setq comint-prompt-regexp ftp-prompt-regexp) | |
544 | |
545 (make-local-variable 'comint-input-autoexpand) | |
546 (setq comint-input-autoexpand t) | |
547 | |
548 ;; Already buffer local! | |
549 (setq comint-output-filter-functions | |
550 (list 'comint-watch-for-password-prompt)) | |
551 | |
552 (setq local-abbrev-table ftp-mode-abbrev-table) | |
553 (abbrev-mode t) | |
554 ) | |
555 | |
556 (define-abbrev ftp-mode-abbrev-table "q" "quit") | |
557 (define-abbrev ftp-mode-abbrev-table "g" "get") | |
558 (define-abbrev ftp-mode-abbrev-table "p" "prompt") | |
559 (define-abbrev ftp-mode-abbrev-table "anon" "anonymous") | |
560 | |
561 ;; Occasionally useful | |
562 (define-key ftp-mode-map "\t" 'comint-dynamic-complete) | |
563 | |
564 (defun smbclient (host service) | |
565 "Connect to SERVICE on HOST via SMB." | |
566 (interactive | |
567 (list | |
568 (read-from-minibuffer | |
569 "Connect to Host: " (net-utils-machine-at-point)) | |
570 (read-from-minibuffer "SMB Service: "))) | |
571 (require 'comint) | |
572 (let* ((name (format "smbclient [%s\\%s]" host service)) | |
573 (buf (get-buffer-create (concat "*" name "*"))) | |
574 (service-name (concat "\\\\" host "\\" service))) | |
575 (set-buffer buf) | |
576 (comint-mode) | |
577 (comint-exec buf name smbclient-program nil | |
578 (if smbclient-program-options | |
579 (append (list service-name) smbclient-program-options) | |
580 (list service-name))) | |
581 (smbclient-mode) | |
582 (switch-to-buffer-other-window buf) | |
583 )) | |
584 | |
585 (defun smbclient-list-shares (host) | |
586 "List services on HOST." | |
587 (interactive | |
588 (list | |
589 (read-from-minibuffer | |
590 "Connect to Host: " (net-utils-machine-at-point)) | |
591 )) | |
592 (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host)))) | |
593 (set-buffer buf) | |
594 (comint-mode) | |
595 (comint-exec | |
596 buf | |
597 "smbclient-list-shares" | |
598 smbclient-program | |
599 nil | |
600 (list "-L" host) | |
601 ) | |
602 (smbclient-mode) | |
603 (switch-to-buffer-other-window buf))) | |
604 | |
605 (define-derived-mode | |
606 smbclient-mode comint-mode "smbclient" | |
607 "Major mode for interacting with the smbclient program." | |
608 | |
609 (set | |
610 (make-local-variable 'font-lock-defaults) | |
611 '((smbclient-font-lock-keywords))) | |
612 | |
613 (make-local-variable 'comint-prompt-regexp) | |
614 (setq comint-prompt-regexp smbclient-prompt-regexp) | |
615 | |
616 (make-local-variable 'comint-input-autoexpand) | |
617 (setq comint-input-autoexpand t) | |
618 | |
619 ;; Already buffer local! | |
620 (setq comint-output-filter-functions | |
621 (list 'comint-watch-for-password-prompt)) | |
622 | |
623 (setq local-abbrev-table smbclient-mode-abbrev-table) | |
624 (abbrev-mode t) | |
625 ) | |
626 | |
627 (define-abbrev smbclient-mode-abbrev-table "q" "quit") | |
628 | |
629 | |
630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
631 ;; Network Connections | |
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
633 | |
634 ;; Full list is available at: | |
635 ;; ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers | |
636 (defvar network-connection-service-alist | |
637 (list | |
638 (cons 'echo 7) | |
639 (cons 'active-users 11) | |
640 (cons 'daytime 13) | |
641 (cons 'chargen 19) | |
642 (cons 'ftp 21) | |
643 (cons 'telnet 23) | |
644 (cons 'smtp 25) | |
645 (cons 'time 37) | |
646 (cons 'whois 43) | |
647 (cons 'gopher 70) | |
648 (cons 'finger 79) | |
649 (cons 'www 80) | |
650 (cons 'pop2 109) | |
651 (cons 'pop3 110) | |
652 (cons 'sun-rpc 111) | |
653 (cons 'nntp 119) | |
654 (cons 'ntp 123) | |
655 (cons 'netbios-name 137) | |
656 (cons 'netbios-data 139) | |
657 (cons 'irc 194) | |
658 (cons 'https 443) | |
659 (cons 'rlogin 513) | |
660 ) | |
661 "Alist of services and associated TCP port numbers. | |
662 This list in not complete.") | |
663 | |
664 ;; Workhorse macro | |
665 (defmacro run-network-program (process-name host port | |
666 &optional initial-string) | |
667 ` | |
668 (let ((tcp-connection) | |
669 (buf) | |
670 ) | |
671 (setq buf (get-buffer-create (concat "*" ,process-name "*"))) | |
672 (set-buffer buf) | |
673 (or | |
674 (setq tcp-connection | |
675 (open-network-stream | |
676 ,process-name | |
677 buf | |
678 ,host | |
679 ,port | |
680 )) | |
681 (error "Could not open connection to %s" ,host)) | |
682 (erase-buffer) | |
683 (set-marker (process-mark tcp-connection) (point-min)) | |
684 (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter) | |
685 (and ,initial-string | |
686 (process-send-string tcp-connection | |
687 (concat ,initial-string "\r\n"))) | |
688 (display-buffer buf))) | |
689 | |
690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
691 ;; Simple protocols | |
692 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
693 | |
29303
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
694 (defcustom finger-X.500-host-regexps nil |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
695 "A list of regular expressions matching host names. |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
696 If a host name passed to `finger' matches one of these regular |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
697 expressions, it is assumed to be a host that doesn't accept |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
698 queries of the form USER@HOST, and wants a query containing USER only." |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
699 :group 'net-utils |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
700 :type '(repeat regexp) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
701 :version "21.1") |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
702 |
28210 | 703 ;; Finger protocol |
704 ;;;###autoload | |
705 (defun finger (user host) | |
706 "Finger USER on HOST." | |
707 ;; One of those great interactive statements that's actually | |
708 ;; longer than the function call! The idea is that if the user | |
709 ;; uses a string like "pbreton@cs.umb.edu", we won't ask for the | |
710 ;; host name. If we don't see an "@", we'll prompt for the host. | |
711 (interactive | |
712 (let* ((answer (read-from-minibuffer "Finger User: " | |
713 (net-utils-url-at-point))) | |
714 (index (string-match (regexp-quote "@") answer))) | |
715 (if index | |
29303
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
716 (list (substring answer 0 index) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
717 (substring answer (1+ index))) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
718 (list answer |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
719 (read-from-minibuffer "At Host: " |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
720 (net-utils-machine-at-point)))))) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
721 (let* ((user-and-host (concat user "@" host)) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
722 (process-name (concat "Finger [" user-and-host "]")) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
723 (regexps finger-X.500-host-regexps) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
724 found) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
725 (while (not (string-match (car regexps) host)) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
726 (setq regexps (cdr regexps))) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
727 (when regexps |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
728 (setq user-and-host user)) |
28210 | 729 (run-network-program |
730 process-name | |
731 host | |
732 (cdr (assoc 'finger network-connection-service-alist)) | |
29303
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
733 user-and-host))) |
28210 | 734 |
735 (defcustom whois-server-name "rs.internic.net" | |
736 "Default host name for the whois service." | |
737 :group 'net-utils | |
738 :type 'string | |
739 ) | |
740 | |
741 (defcustom whois-server-list | |
742 '(("whois.arin.net") ; Networks, ASN's, and related POC's (numbers) | |
743 ("rs.internic.net") ; domain related info | |
744 ("whois.abuse.net") | |
745 ("whois.apnic.net") | |
746 ("nic.ddn.mil") | |
747 ("whois.nic.mil") | |
748 ("whois.nic.gov") | |
749 ("whois.ripe.net")) | |
750 "A list of whois servers that can be queried." | |
751 :group 'net-utils | |
752 :type '(repeat (list string))) | |
753 | |
754 (defcustom whois-server-tld | |
755 '(("rs.internic.net" . "com") | |
756 ("rs.internic.net" . "org") | |
757 ("whois.ripe.net" . "be") | |
758 ("whois.ripe.net" . "de") | |
759 ("whois.ripe.net" . "dk") | |
760 ("whois.ripe.net" . "it") | |
761 ("whois.ripe.net" . "fi") | |
762 ("whois.ripe.net" . "fr") | |
763 ("whois.ripe.net" . "uk") | |
764 ("whois.apnic.net" . "au") | |
765 ("whois.apnic.net" . "ch") | |
766 ("whois.apnic.net" . "hk") | |
767 ("whois.apnic.net" . "jp") | |
768 ("whois.nic.gov" . "gov") | |
769 ("whois.nic.mil" . "mil")) | |
770 "Alist to map top level domains to whois servers." | |
771 :group 'net-utils | |
772 :type '(repeat (cons string string))) | |
773 | |
774 (defcustom whois-guess-server t | |
775 "If non-nil then whois will try to deduce the appropriate whois | |
776 server from the query. If the query doesn't look like a domain or hostname | |
777 then the server named by whois-server-name is used." | |
778 :group 'net-utils | |
779 :type 'boolean) | |
780 | |
781 (defun whois-get-tld (host) | |
782 "Return the top level domain of `host', or nil if it isn't a domain name." | |
783 (let ((i (1- (length host))) | |
784 (max-len (- (length host) 5))) | |
785 (while (not (or (= i max-len) (char-equal (aref host i) ?.))) | |
786 (setq i (1- i))) | |
787 (if (= i max-len) | |
788 nil | |
789 (substring host (1+ i))))) | |
790 | |
791 ;; Whois protocol | |
792 ;;;###autoload | |
793 (defun whois (arg search-string) | |
794 "Send SEARCH-STRING to server defined by the `whois-server-name' variable. | |
795 If `whois-guess-server' is non-nil, then try to deduce the correct server | |
796 from SEARCH-STRING. With argument, prompt for whois server." | |
797 (interactive "P\nsWhois: ") | |
798 (let* ((whois-apropos-host (if whois-guess-server | |
799 (rassoc (whois-get-tld search-string) | |
800 whois-server-tld) | |
801 nil)) | |
802 (server-name (if whois-apropos-host | |
803 (car whois-apropos-host) | |
804 whois-server-name)) | |
805 (host | |
806 (if arg | |
807 (completing-read "Whois server name: " | |
808 whois-server-list nil nil "whois.") | |
809 server-name))) | |
810 (run-network-program | |
811 "Whois" | |
812 host | |
813 (cdr (assoc 'whois network-connection-service-alist)) | |
814 search-string | |
815 ))) | |
816 | |
817 (defcustom whois-reverse-lookup-server "whois.arin.net" | |
818 "Server which provides inverse DNS mapping." | |
819 :group 'net-utils | |
820 :type 'string | |
821 ) | |
822 | |
823 ;;;###autoload | |
824 (defun whois-reverse-lookup () | |
825 (interactive) | |
826 (let ((whois-server-name whois-reverse-lookup-server)) | |
827 (call-interactively 'whois))) | |
828 | |
829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
830 ;;; General Network connection | |
831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
832 | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
833 ;; Using a derived mode gives us keymaps, hooks, etc. |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
834 (define-derived-mode |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
835 network-connection-mode comint-mode "Network-Connection" |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
836 "Major mode for interacting with the network-connection program." |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
837 ) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
838 |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
839 (defun network-connection-mode-setup (host service) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
840 (let ((network-abbrev-table |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
841 (or |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
842 (assoc service network-connection-service-abbrev-alist) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
843 (and (rassoc service network-connection-service-alist) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
844 (assoc |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
845 (elt (rassoc service network-connection-service-alist) 0) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
846 network-connection-service-abbrev-alist))))) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
847 (make-local-variable 'network-connection-host) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
848 (setq network-connection-host host) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
849 (make-local-variable 'network-connection-service) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
850 (setq network-connection-service service) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
851 (and network-abbrev-table |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
852 (setq local-abbrev-table (cdr network-abbrev-table)) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
853 (abbrev-mode t) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
854 ))) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
855 |
28210 | 856 ;;;###autoload |
857 (defun network-connection-to-service (host service) | |
858 "Open a network connection to SERVICE on HOST." | |
859 (interactive | |
860 (list | |
861 (read-from-minibuffer "Host: " (net-utils-machine-at-point)) | |
862 (completing-read "Service: " | |
863 (mapcar | |
864 (function | |
865 (lambda (elt) | |
866 (list (symbol-name (car elt))))) | |
867 network-connection-service-alist)))) | |
868 (network-connection | |
869 host | |
870 (cdr (assoc (intern service) network-connection-service-alist))) | |
871 ) | |
872 | |
873 ;;;###autoload | |
874 (defun network-connection (host port) | |
875 "Open a network connection to HOST on PORT." | |
876 (interactive "sHost: \nnPort: ") | |
877 (network-service-connection host (number-to-string port))) | |
878 | |
879 (defun network-service-connection (host service) | |
880 "Open a network connection to SERVICE on HOST." | |
881 (require 'comint) | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
882 (let* ( |
28210 | 883 (process-name (concat "Network Connection [" host " " service "]")) |
884 (portnum (string-to-number service)) | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
885 (buf (get-buffer-create (concat "*" process-name "*"))) |
28210 | 886 ) |
887 (or (zerop portnum) (setq service portnum)) | |
888 (make-comint | |
889 process-name | |
890 (cons host service)) | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
891 (set-buffer buf) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
892 (network-connection-mode) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
893 (network-connection-mode-setup host service) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
894 (pop-to-buffer buf) |
28210 | 895 )) |
896 | |
897 (provide 'net-utils) | |
898 | |
899 ;;; net-utils.el ends here |