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