comparison lisp/net-utils.el @ 23391:4120f9e06191

(ftp, nslookup): Require comint. (network-service-connection): Likewise. (whois-server-name): Defaults to whois.arin.net (whois-server-list, whois-server-tld, whois-guess-server): New var. (whois): Tries to guess the appropriate top-level domain server. (whois-get-tld): New function.
author Karl Heuer <kwzh@gnu.org>
date Tue, 06 Oct 1998 23:59:00 +0000
parents 0757f6ee2e53
children 8256c4d22113
comparison
equal deleted inserted replaced
23390:ce9dd8548989 23391:4120f9e06191
438 438
439 ;;;###autoload 439 ;;;###autoload
440 (defun nslookup () 440 (defun nslookup ()
441 "Run nslookup program." 441 "Run nslookup program."
442 (interactive) 442 (interactive)
443 (require 'comint)
443 (comint-run nslookup-program) 444 (comint-run nslookup-program)
444 (set-process-filter (get-buffer-process "*nslookup*") 445 (set-process-filter (get-buffer-process "*nslookup*")
445 'net-utils-remove-ctrl-m-filter) 446 'net-utils-remove-ctrl-m-filter)
446 (set 447 (set
447 (make-local-variable 'font-lock-defaults) 448 (make-local-variable 'font-lock-defaults)
457 ;; This is a lot less than ange-ftp, but much simpler. 458 ;; This is a lot less than ange-ftp, but much simpler.
458 ;;;###autoload 459 ;;;###autoload
459 (defun ftp (host) 460 (defun ftp (host)
460 "Run ftp program." 461 "Run ftp program."
461 (interactive "sFtp to Host: ") 462 (interactive "sFtp to Host: ")
463 (require 'comint)
462 (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) 464 (let ((buf (get-buffer-create (concat "*ftp [" host "]*"))))
463 (set-buffer buf) 465 (set-buffer buf)
464 (comint-mode) 466 (comint-mode)
465 (comint-exec buf (concat "ftp-" host) ftp-program nil 467 (comint-exec buf (concat "ftp-" host) ftp-program nil
466 (if ftp-program-options 468 (if ftp-program-options
576 host 578 host
577 (cdr (assoc 'finger network-connection-service-alist)) 579 (cdr (assoc 'finger network-connection-service-alist))
578 user-and-host 580 user-and-host
579 ))) 581 )))
580 582
581 (defcustom whois-server-name "whois.internic.net" 583 (defcustom whois-server-name "whois.arin.net"
582 "Host name for the whois service." 584 "Default host name for the whois service."
583 :group 'net-utils 585 :group 'net-utils
584 :type 'string 586 :type 'string
585 ) 587 )
588
589 (defcustom whois-server-list
590 '(("whois.arin.net") ; Networks, ASN's, and related POC's (numbers)
591 ("rs.internic.net") ; domain related info
592 ("whois.abuse.net")
593 ("whois.apnic.net")
594 ("nic.ddn.mil")
595 ("whois.nic.mil")
596 ("whois.nic.gov")
597 ("whois.ripe.net"))
598 "A list of whois servers that can be queried."
599 :group 'net-utils
600 :type '(repeat (list)))
601
602 (defcustom whois-server-tld
603 '(("rs.internic.net" . "com")
604 ("rs.internic.net" . "org")
605 ("whois.ripe.net" . "be")
606 ("whois.ripe.net" . "de")
607 ("whois.ripe.net" . "dk")
608 ("whois.ripe.net" . "it")
609 ("whois.ripe.net" . "fi")
610 ("whois.ripe.net" . "fr")
611 ("whois.ripe.net" . "uk")
612 ("whois.apnic.net" . "au")
613 ("whois.apnic.net" . "ch")
614 ("whois.apnic.net" . "hk")
615 ("whois.apnic.net" . "jp")
616 ("whois.nic.gov" . "gov")
617 ("whois.nic.mil" . "mil"))
618 "Alist to map top level domains to whois servers."
619 :group 'net-utils
620 :type '(repeat (cons string string)))
621
622 (defcustom whois-guess-server t
623 "If non-nil then whois will try to deduce the appropriate whois
624 server from the query. If the query doesn't look like a domain or hostname
625 then the server named by whois-server-name is used."
626 :group 'net-utils
627 :type 'boolean)
628
629
630 (defun whois-get-tld (host)
631 (do ((i (1- (length host)) (1- i))
632 (max-len (- (length host) 4)))
633 ((or (= i max-len) (char-equal (aref host i) ?.))
634 (if (= i max-len) nil
635 (substring host (1+ i))))))
586 636
587 ;; Whois protocol 637 ;; Whois protocol
588 ;;;###autoload 638 ;;;###autoload
589 (defun whois (arg search-string) 639 (defun whois (arg search-string)
590 "Send SEARCH-STRING to server defined by the `whois-server-name' variable. 640 "Send SEARCH-STRING to server defined by the `whois-server-name' variable.
591 With argument, prompt for whois server." 641 If `whois-guess-server' is non-nil, then try to deduce the correct server
642 from SEARCH-STRING. With argument, prompt for whois server."
592 (interactive "P\nsWhois: ") 643 (interactive "P\nsWhois: ")
593 (let ((host 644 (let* ((whois-apropos-host (if whois-guess-server
594 (if arg 645 (rassoc (whois-get-tld search-string)
595 (read-from-minibuffer "Whois server name: ") 646 whois-server-tld)
596 whois-server-name)) 647 nil))
597 ) 648 (server-name (if whois-apropos-host
649 (car whois-apropos-host)
650 whois-server-name))
651 (host
652 (if arg
653 (completing-read "Whois server name: "
654 whois-server-list nil nil "whois.")
655 server-name)))
598 (run-network-program 656 (run-network-program
599 "Whois" 657 "Whois"
600 host 658 host
601 (cdr (assoc 'whois network-connection-service-alist)) 659 (cdr (assoc 'whois network-connection-service-alist))
602 search-string 660 search-string
641 (interactive "sHost: \nnPort: ") 699 (interactive "sHost: \nnPort: ")
642 (network-service-connection host (number-to-string port))) 700 (network-service-connection host (number-to-string port)))
643 701
644 (defun network-service-connection (host service) 702 (defun network-service-connection (host service)
645 "Open a network connection to SERVICE on HOST." 703 "Open a network connection to SERVICE on HOST."
704 (require 'comint)
646 (let ( 705 (let (
647 (process-name (concat "Network Connection [" host " " service "]")) 706 (process-name (concat "Network Connection [" host " " service "]"))
648 (portnum (string-to-number service)) 707 (portnum (string-to-number service))
649 ) 708 )
650 (or (zerop portnum) (setq service portnum)) 709 (or (zerop portnum) (setq service portnum))