Mercurial > emacs
annotate lisp/net/net-utils.el @ 32123:2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
ftp-font-lock-keywords, smbclient-font-lock-keywords):
Only set if window-system is non-nil
(net-utils-run-program): Returns buffer.
(network-connection-reconnect): Added this function.
author | Peter Breton <pbreton@attbi.com> |
---|---|
date | Wed, 04 Oct 2000 05:43:37 +0000 |
parents | 716c9bd98063 |
children | b048135b76bc |
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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
6 ;; Time-stamp: <2000-10-04 01:32:16 pbreton> |
28210 | 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: | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
28 ;; |
28210 | 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. | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
32 ;; |
28210 | 33 ;; * 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
|
34 ;; |
28210 | 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, | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
42 ;; but rather in /sbin, /usr/sbin, and so on. |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
60 (defcustom net-utils-remove-ctl-m |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
67 (defcustom traceroute-program |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
68 (if (eq system-type 'windows-nt) |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
90 (defcustom ping-program-options |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
99 (defcustom ipconfig-program |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
109 (list |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
123 (defcustom netstat-program-options |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
136 (defcustom arp-program-options |
28210 | 137 (list "-a") |
138 "Options for arp-program." | |
139 :group 'net-utils | |
140 :type '(repeat string) | |
141 ) | |
142 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
143 (defcustom route-program |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
152 (defcustom route-program-options |
28210 | 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 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
230 (and window-system |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
231 (progn |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
232 (require 'font-lock) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
233 (list |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
234 (list nslookup-prompt-regexp 0 font-lock-reference-face) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
235 (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
236 (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
237 1 font-lock-keyword-face) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
238 ;; Dotted quads |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
239 (list |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
240 (mapconcat 'identity |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
241 (make-list 4 "[0-9]+") |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
242 "\\.") |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
243 0 font-lock-variable-name-face) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
244 ;; Host names |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
245 (list |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
246 (let ((host-expression "[-A-Za-z0-9]+")) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
247 (concat |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
248 (mapconcat 'identity |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
249 (make-list 2 host-expression) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
250 "\\.") |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
251 "\\(\\." host-expression "\\)*") |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
252 ) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
253 0 font-lock-variable-name-face) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
254 ))) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
255 "Expressions to font-lock for nslookup.") |
28210 | 256 |
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
258 ;; FTP goodies | |
259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
260 | |
261 (defconst ftp-font-lock-keywords | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
262 (and window-system |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
263 (progn |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
264 (require 'font-lock) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
265 (list |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
266 (list ftp-prompt-regexp 0 font-lock-reference-face))))) |
28210 | 267 |
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
269 ;; smbclient goodies | |
270 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
271 | |
272 (defconst smbclient-font-lock-keywords | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
273 (and window-system |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
274 (progn |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
275 (require 'font-lock) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
276 (list |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
277 (list smbclient-prompt-regexp 0 font-lock-reference-face))))) |
28210 | 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))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
317 |
28210 | 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)))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
329 |
28210 | 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") | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
336 (set-process-filter |
28210 | 337 (apply 'start-process ,name buf ,program ,@args) |
338 '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
|
339 (display-buffer buf) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
340 buf)) |
28210 | 341 |
342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
343 ;; Wrappers for external network programs | |
344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
345 | |
346 ;;;###autoload | |
347 (defun traceroute (target) | |
348 "Run traceroute program for TARGET." | |
349 (interactive "sTarget: ") | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
350 (let ((options |
28210 | 351 (if traceroute-program-options |
352 (append traceroute-program-options (list target)) | |
353 (list target)))) | |
354 (net-utils-run-program | |
355 (concat "Traceroute" " " target) | |
356 (concat "** Traceroute ** " traceroute-program " ** " target) | |
357 traceroute-program | |
358 options | |
359 ))) | |
360 | |
361 ;;;###autoload | |
362 (defun ping (host) | |
363 "Ping HOST. | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
364 If your system's ping continues until interrupted, you can try setting |
28210 | 365 `ping-program-options'." |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
366 (interactive |
28210 | 367 (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
|
368 (let ((options |
28210 | 369 (if ping-program-options |
370 (append ping-program-options (list host)) | |
371 (list host)))) | |
372 (net-utils-run-program | |
373 (concat "Ping" " " host) | |
374 (concat "** Ping ** " ping-program " ** " host) | |
375 ping-program | |
376 options | |
377 ))) | |
378 | |
379 ;;;###autoload | |
380 (defun ipconfig () | |
381 "Run ipconfig program." | |
382 (interactive) | |
383 (net-utils-run-program | |
384 "Ipconfig" | |
385 (concat "** Ipconfig ** " ipconfig-program " ** ") | |
386 ipconfig-program | |
387 ipconfig-program-options | |
388 )) | |
389 | |
390 ;; This is the normal name on most Unixes. | |
391 ;;;###autoload | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
392 (defalias 'ifconfig 'ipconfig) |
28210 | 393 |
394 ;;;###autoload | |
395 (defun netstat () | |
396 "Run netstat program." | |
397 (interactive) | |
398 (net-utils-run-program | |
399 "Netstat" | |
400 (concat "** Netstat ** " netstat-program " ** ") | |
401 netstat-program | |
402 netstat-program-options | |
403 )) | |
404 | |
405 ;;;###autoload | |
406 (defun arp () | |
407 "Run the arp program." | |
408 (interactive) | |
409 (net-utils-run-program | |
410 "Arp" | |
411 (concat "** Arp ** " arp-program " ** ") | |
412 arp-program | |
413 arp-program-options | |
414 )) | |
415 | |
416 ;;;###autoload | |
417 (defun route () | |
418 "Run the route program." | |
419 (interactive) | |
420 (net-utils-run-program | |
421 "Route" | |
422 (concat "** Route ** " route-program " ** ") | |
423 route-program | |
424 route-program-options | |
425 )) | |
426 | |
427 ;; FIXME -- Needs to be a process filter | |
428 ;; (defun netstat-with-filter (filter) | |
429 ;; "Run netstat program." | |
430 ;; (interactive "sFilter: ") | |
431 ;; (netstat) | |
432 ;; (set-buffer (get-buffer "*Netstat*")) | |
433 ;; (goto-char (point-min)) | |
434 ;; (delete-matching-lines filter) | |
435 ;; ) | |
436 | |
437 ;;;###autoload | |
438 (defun nslookup-host (host) | |
439 "Lookup the DNS information for HOST." | |
440 (interactive | |
441 (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
|
442 (let ((options |
28210 | 443 (if nslookup-program-options |
444 (append nslookup-program-options (list host)) | |
445 (list host)))) | |
446 (net-utils-run-program | |
447 "Nslookup" | |
448 (concat "** " | |
449 (mapconcat 'identity | |
450 (list "Nslookup" host nslookup-program) | |
451 " ** ")) | |
452 nslookup-program | |
453 options | |
454 ))) | |
455 | |
456 | |
457 ;;;###autoload | |
458 (defun nslookup () | |
459 "Run nslookup program." | |
460 (interactive) | |
461 (require 'comint) | |
462 (comint-run nslookup-program) | |
463 (set-process-filter (get-buffer-process "*nslookup*") | |
464 'net-utils-remove-ctrl-m-filter) | |
465 (nslookup-mode) | |
466 ) | |
467 | |
468 ;; 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
|
469 (define-derived-mode |
28210 | 470 nslookup-mode comint-mode "Nslookup" |
471 "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
|
472 (set |
28210 | 473 (make-local-variable 'font-lock-defaults) |
474 '((nslookup-font-lock-keywords))) | |
475 (setq local-abbrev-table nslookup-mode-abbrev-table) | |
476 (abbrev-mode t) | |
477 (make-local-variable 'comint-prompt-regexp) | |
478 (setq comint-prompt-regexp nslookup-prompt-regexp) | |
479 (make-local-variable 'comint-input-autoexpand) | |
480 (setq comint-input-autoexpand t) | |
481 ) | |
482 | |
483 (define-key nslookup-mode-map "\t" 'comint-dynamic-complete) | |
484 | |
485 (define-abbrev nslookup-mode-abbrev-table "e" "exit") | |
486 (define-abbrev nslookup-mode-abbrev-table "f" "finger") | |
487 (define-abbrev nslookup-mode-abbrev-table "h" "help") | |
488 (define-abbrev nslookup-mode-abbrev-table "lse" "lserver") | |
489 (define-abbrev nslookup-mode-abbrev-table "q" "exit") | |
490 (define-abbrev nslookup-mode-abbrev-table "r" "root") | |
491 (define-abbrev nslookup-mode-abbrev-table "s" "set") | |
492 (define-abbrev nslookup-mode-abbrev-table "se" "server") | |
493 (define-abbrev nslookup-mode-abbrev-table "v" "viewer") | |
494 | |
495 ;;;###autoload | |
496 (defun dig (host) | |
497 "Run dig program." | |
498 (interactive | |
499 (list | |
500 (progn | |
501 (require 'ffap) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
502 (read-from-minibuffer |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
503 "Lookup host: " |
28210 | 504 (or (ffap-string-at-point 'machine) ""))))) |
505 (net-utils-run-program | |
506 "Dig" | |
507 (concat "** " | |
508 (mapconcat 'identity | |
509 (list "Dig" host dig-program) | |
510 " ** ")) | |
511 dig-program | |
512 (list host) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
513 )) |
28210 | 514 |
515 ;; This is a lot less than ange-ftp, but much simpler. | |
516 ;;;###autoload | |
517 (defun ftp (host) | |
518 "Run ftp program." | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
519 (interactive |
28210 | 520 (list |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
521 (read-from-minibuffer |
28210 | 522 "Ftp to Host: " (net-utils-machine-at-point)))) |
523 (require 'comint) | |
524 (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) | |
525 (set-buffer buf) | |
526 (comint-mode) | |
527 (comint-exec buf (concat "ftp-" host) ftp-program nil | |
528 (if ftp-program-options | |
529 (append (list host) ftp-program-options) | |
530 (list host))) | |
531 (ftp-mode) | |
532 (switch-to-buffer-other-window buf) | |
533 )) | |
534 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
535 (define-derived-mode |
28210 | 536 ftp-mode comint-mode "FTP" |
537 "Major mode for interacting with the ftp program." | |
538 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
539 (set |
28210 | 540 (make-local-variable 'font-lock-defaults) |
541 '((ftp-font-lock-keywords))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
542 |
28210 | 543 (make-local-variable 'comint-prompt-regexp) |
544 (setq comint-prompt-regexp ftp-prompt-regexp) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
545 |
28210 | 546 (make-local-variable 'comint-input-autoexpand) |
547 (setq comint-input-autoexpand t) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
548 |
28210 | 549 ;; Already buffer local! |
550 (setq comint-output-filter-functions | |
551 (list 'comint-watch-for-password-prompt)) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
552 |
28210 | 553 (setq local-abbrev-table ftp-mode-abbrev-table) |
554 (abbrev-mode t) | |
555 ) | |
556 | |
557 (define-abbrev ftp-mode-abbrev-table "q" "quit") | |
558 (define-abbrev ftp-mode-abbrev-table "g" "get") | |
559 (define-abbrev ftp-mode-abbrev-table "p" "prompt") | |
560 (define-abbrev ftp-mode-abbrev-table "anon" "anonymous") | |
561 | |
562 ;; Occasionally useful | |
563 (define-key ftp-mode-map "\t" 'comint-dynamic-complete) | |
564 | |
565 (defun smbclient (host service) | |
566 "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
|
567 (interactive |
28210 | 568 (list |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
569 (read-from-minibuffer |
28210 | 570 "Connect to Host: " (net-utils-machine-at-point)) |
571 (read-from-minibuffer "SMB Service: "))) | |
572 (require 'comint) | |
573 (let* ((name (format "smbclient [%s\\%s]" host service)) | |
574 (buf (get-buffer-create (concat "*" name "*"))) | |
575 (service-name (concat "\\\\" host "\\" service))) | |
576 (set-buffer buf) | |
577 (comint-mode) | |
578 (comint-exec buf name smbclient-program nil | |
579 (if smbclient-program-options | |
580 (append (list service-name) smbclient-program-options) | |
581 (list service-name))) | |
582 (smbclient-mode) | |
583 (switch-to-buffer-other-window buf) | |
584 )) | |
585 | |
586 (defun smbclient-list-shares (host) | |
587 "List services on HOST." | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
588 (interactive |
28210 | 589 (list |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
590 (read-from-minibuffer |
28210 | 591 "Connect to Host: " (net-utils-machine-at-point)) |
592 )) | |
593 (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host)))) | |
594 (set-buffer buf) | |
595 (comint-mode) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
596 (comint-exec |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
597 buf |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
598 "smbclient-list-shares" |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
599 smbclient-program |
28210 | 600 nil |
601 (list "-L" host) | |
602 ) | |
603 (smbclient-mode) | |
604 (switch-to-buffer-other-window buf))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
605 |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
606 (define-derived-mode |
28210 | 607 smbclient-mode comint-mode "smbclient" |
608 "Major mode for interacting with the smbclient program." | |
609 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
610 (set |
28210 | 611 (make-local-variable 'font-lock-defaults) |
612 '((smbclient-font-lock-keywords))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
613 |
28210 | 614 (make-local-variable 'comint-prompt-regexp) |
615 (setq comint-prompt-regexp smbclient-prompt-regexp) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
616 |
28210 | 617 (make-local-variable 'comint-input-autoexpand) |
618 (setq comint-input-autoexpand t) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
619 |
28210 | 620 ;; Already buffer local! |
621 (setq comint-output-filter-functions | |
622 (list 'comint-watch-for-password-prompt)) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
623 |
28210 | 624 (setq local-abbrev-table smbclient-mode-abbrev-table) |
625 (abbrev-mode t) | |
626 ) | |
627 | |
628 (define-abbrev smbclient-mode-abbrev-table "q" "quit") | |
629 | |
630 | |
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
632 ;; Network Connections | |
633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
634 | |
635 ;; Full list is available at: | |
636 ;; 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
|
637 (defvar network-connection-service-alist |
28210 | 638 (list |
639 (cons 'echo 7) | |
640 (cons 'active-users 11) | |
641 (cons 'daytime 13) | |
642 (cons 'chargen 19) | |
643 (cons 'ftp 21) | |
644 (cons 'telnet 23) | |
645 (cons 'smtp 25) | |
646 (cons 'time 37) | |
647 (cons 'whois 43) | |
648 (cons 'gopher 70) | |
649 (cons 'finger 79) | |
650 (cons 'www 80) | |
651 (cons 'pop2 109) | |
652 (cons 'pop3 110) | |
653 (cons 'sun-rpc 111) | |
654 (cons 'nntp 119) | |
655 (cons 'ntp 123) | |
656 (cons 'netbios-name 137) | |
657 (cons 'netbios-data 139) | |
658 (cons 'irc 194) | |
659 (cons 'https 443) | |
660 (cons 'rlogin 513) | |
661 ) | |
662 "Alist of services and associated TCP port numbers. | |
663 This list in not complete.") | |
664 | |
665 ;; Workhorse macro | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
666 (defmacro run-network-program (process-name host port |
28210 | 667 &optional initial-string) |
668 ` | |
669 (let ((tcp-connection) | |
670 (buf) | |
671 ) | |
672 (setq buf (get-buffer-create (concat "*" ,process-name "*"))) | |
673 (set-buffer buf) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
674 (or |
28210 | 675 (setq tcp-connection |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
676 (open-network-stream |
28210 | 677 ,process-name |
678 buf | |
679 ,host | |
680 ,port | |
681 )) | |
682 (error "Could not open connection to %s" ,host)) | |
683 (erase-buffer) | |
684 (set-marker (process-mark tcp-connection) (point-min)) | |
685 (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter) | |
686 (and ,initial-string | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
687 (process-send-string tcp-connection |
28210 | 688 (concat ,initial-string "\r\n"))) |
689 (display-buffer buf))) | |
690 | |
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
692 ;; Simple protocols | |
693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
694 | |
29303
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
695 (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
|
696 "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
|
697 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
|
698 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
|
699 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
|
700 :group 'net-utils |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
701 :type '(repeat regexp) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
702 :version "21.1") |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
703 |
28210 | 704 ;; Finger protocol |
705 ;;;###autoload | |
706 (defun finger (user host) | |
707 "Finger USER on HOST." | |
708 ;; One of those great interactive statements that's actually | |
709 ;; longer than the function call! The idea is that if the user | |
710 ;; uses a string like "pbreton@cs.umb.edu", we won't ask for the | |
711 ;; host name. If we don't see an "@", we'll prompt for the host. | |
712 (interactive | |
713 (let* ((answer (read-from-minibuffer "Finger User: " | |
714 (net-utils-url-at-point))) | |
715 (index (string-match (regexp-quote "@") answer))) | |
716 (if index | |
29303
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
717 (list (substring answer 0 index) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
718 (substring answer (1+ index))) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
719 (list answer |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
720 (read-from-minibuffer "At Host: " |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
721 (net-utils-machine-at-point)))))) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
722 (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
|
723 (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
|
724 (regexps finger-X.500-host-regexps) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
725 found) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
726 (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
|
727 (setq regexps (cdr regexps))) |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
728 (when regexps |
a3541330de52
(finger-X.500-host-regexps): New user-option.
Gerd Moellmann <gerd@gnu.org>
parents:
28419
diff
changeset
|
729 (setq user-and-host user)) |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
730 (run-network-program |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
731 process-name |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
732 host |
28210 | 733 (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
|
734 user-and-host))) |
28210 | 735 |
736 (defcustom whois-server-name "rs.internic.net" | |
737 "Default host name for the whois service." | |
738 :group 'net-utils | |
739 :type 'string | |
740 ) | |
741 | |
742 (defcustom whois-server-list | |
743 '(("whois.arin.net") ; Networks, ASN's, and related POC's (numbers) | |
744 ("rs.internic.net") ; domain related info | |
745 ("whois.abuse.net") | |
746 ("whois.apnic.net") | |
747 ("nic.ddn.mil") | |
748 ("whois.nic.mil") | |
749 ("whois.nic.gov") | |
750 ("whois.ripe.net")) | |
751 "A list of whois servers that can be queried." | |
752 :group 'net-utils | |
753 :type '(repeat (list string))) | |
754 | |
755 (defcustom whois-server-tld | |
756 '(("rs.internic.net" . "com") | |
757 ("rs.internic.net" . "org") | |
758 ("whois.ripe.net" . "be") | |
759 ("whois.ripe.net" . "de") | |
760 ("whois.ripe.net" . "dk") | |
761 ("whois.ripe.net" . "it") | |
762 ("whois.ripe.net" . "fi") | |
763 ("whois.ripe.net" . "fr") | |
764 ("whois.ripe.net" . "uk") | |
765 ("whois.apnic.net" . "au") | |
766 ("whois.apnic.net" . "ch") | |
767 ("whois.apnic.net" . "hk") | |
768 ("whois.apnic.net" . "jp") | |
769 ("whois.nic.gov" . "gov") | |
770 ("whois.nic.mil" . "mil")) | |
771 "Alist to map top level domains to whois servers." | |
772 :group 'net-utils | |
773 :type '(repeat (cons string string))) | |
774 | |
775 (defcustom whois-guess-server t | |
776 "If non-nil then whois will try to deduce the appropriate whois | |
777 server from the query. If the query doesn't look like a domain or hostname | |
778 then the server named by whois-server-name is used." | |
779 :group 'net-utils | |
780 :type 'boolean) | |
781 | |
782 (defun whois-get-tld (host) | |
783 "Return the top level domain of `host', or nil if it isn't a domain name." | |
784 (let ((i (1- (length host))) | |
785 (max-len (- (length host) 5))) | |
786 (while (not (or (= i max-len) (char-equal (aref host i) ?.))) | |
787 (setq i (1- i))) | |
788 (if (= i max-len) | |
789 nil | |
790 (substring host (1+ i))))) | |
791 | |
792 ;; Whois protocol | |
793 ;;;###autoload | |
794 (defun whois (arg search-string) | |
795 "Send SEARCH-STRING to server defined by the `whois-server-name' variable. | |
796 If `whois-guess-server' is non-nil, then try to deduce the correct server | |
797 from SEARCH-STRING. With argument, prompt for whois server." | |
798 (interactive "P\nsWhois: ") | |
799 (let* ((whois-apropos-host (if whois-guess-server | |
800 (rassoc (whois-get-tld search-string) | |
801 whois-server-tld) | |
802 nil)) | |
803 (server-name (if whois-apropos-host | |
804 (car whois-apropos-host) | |
805 whois-server-name)) | |
806 (host | |
807 (if arg | |
808 (completing-read "Whois server name: " | |
809 whois-server-list nil nil "whois.") | |
810 server-name))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
811 (run-network-program |
28210 | 812 "Whois" |
813 host | |
814 (cdr (assoc 'whois network-connection-service-alist)) | |
815 search-string | |
816 ))) | |
817 | |
818 (defcustom whois-reverse-lookup-server "whois.arin.net" | |
819 "Server which provides inverse DNS mapping." | |
820 :group 'net-utils | |
821 :type 'string | |
822 ) | |
823 | |
824 ;;;###autoload | |
825 (defun whois-reverse-lookup () | |
826 (interactive) | |
827 (let ((whois-server-name whois-reverse-lookup-server)) | |
828 (call-interactively 'whois))) | |
829 | |
830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
831 ;;; General Network connection | |
832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
833 | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
834 ;; 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
|
835 (define-derived-mode |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
836 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
|
837 "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
|
838 ) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
839 |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
840 (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
|
841 (let ((network-abbrev-table |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
842 (or |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
843 (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
|
844 (and (rassoc service network-connection-service-alist) |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
845 (assoc |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
846 (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
|
847 network-connection-service-abbrev-alist))))) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
848 (make-local-variable 'network-connection-host) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
849 (setq network-connection-host host) |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
850 (make-local-variable 'network-connection-service) |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
851 (setq network-connection-service service) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
852 (and network-abbrev-table |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
853 (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
|
854 (abbrev-mode t) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
855 ))) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
856 |
28210 | 857 ;;;###autoload |
858 (defun network-connection-to-service (host service) | |
859 "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
|
860 (interactive |
28210 | 861 (list |
862 (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
|
863 (completing-read "Service: " |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
864 (mapcar |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
865 (function |
28210 | 866 (lambda (elt) |
867 (list (symbol-name (car elt))))) | |
868 network-connection-service-alist)))) | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
869 (network-connection |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
870 host |
28210 | 871 (cdr (assoc (intern service) network-connection-service-alist))) |
872 ) | |
873 | |
874 ;;;###autoload | |
875 (defun network-connection (host port) | |
876 "Open a network connection to HOST on PORT." | |
877 (interactive "sHost: \nnPort: ") | |
878 (network-service-connection host (number-to-string port))) | |
879 | |
880 (defun network-service-connection (host service) | |
881 "Open a network connection to SERVICE on HOST." | |
882 (require 'comint) | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
883 (let* ( |
28210 | 884 (process-name (concat "Network Connection [" host " " service "]")) |
885 (portnum (string-to-number service)) | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
886 (buf (get-buffer-create (concat "*" process-name "*"))) |
28210 | 887 ) |
888 (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
|
889 (make-comint |
28210 | 890 process-name |
891 (cons host service)) | |
28419
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
892 (set-buffer buf) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
893 (network-connection-mode) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
894 (network-connection-mode-setup host service) |
fed834403704
network-connection-mode is derived from comint-mode
Peter Breton <pbreton@attbi.com>
parents:
28210
diff
changeset
|
895 (pop-to-buffer buf) |
28210 | 896 )) |
897 | |
32123
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
898 (defun network-connection-reconnect () |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
899 "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
|
900 (interactive) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
901 (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
|
902 (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
|
903 (host network-connection-host) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
904 (service network-connection-service) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
905 ) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
906 (if (not (or (not proc) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
907 (eq (process-status proc) 'closed))) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
908 (message "Still connected") |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
909 (goto-char (point-max)) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
910 (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
|
911 (network-connection host |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
912 (if (numberp service) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
913 service |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
914 (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
|
915 (and old-comint-input-ring |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
916 (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
|
917 ))) |
2e9fda397ea2
* net/net-utils.el (nslookup-font-lock-keywords,
Peter Breton <pbreton@attbi.com>
parents:
30548
diff
changeset
|
918 |
28210 | 919 (provide 'net-utils) |
920 | |
921 ;;; net-utils.el ends here |