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