diff --git a/lisp/ffap.el b/lisp/ffap.el index 9de0dd40d1..a0751fbd8e 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -641,6 +641,25 @@ ffap-fixup-url ((and ffap-url-unwrap-remote (ffap-url-unwrap-remote url))) (url))) + +;;; IP Address (`ffap-ip-p'): + +;;;###autoload +(defun ffap-ip-at-point () + "Return IP address at point if it exists, or nil." + (let ((mach (ffap-string-at-point 'ip))) + (and (ffap-ip-p mach) mach))) + +(defun ffap-ip-p (ip) + "Decide whether IP is a valid IP address." + (when-let* ((start (string-match "\\([0-9]\\{1,3\\}\\.\\)\\{3\\}[0-9]\\{1,3\\}" ip)) + (end (match-end 0)) + (nums (mapcar #'string-to-number (split-string (substring ip start end) "\\.")))) + (message "|%S|%S|%S|" start end (length ip)) + (and (zerop start) + (length= ip end) + (seq-every-p #'(lambda (num) (and (>= num 0) (<= num 255))) nums)))) + ;;; File Name Handling: ;; @@ -1094,6 +1113,8 @@ ffap-string-at-point-mode-alist (nocolon "--9$+<>@-Z_[:alpha:]~" "<@" "@>;.,!?") ;; A machine: (machine "-[:alnum:]." "" ".") + ;; An IP address: + (ip "[0-9]." "" ".") ;; Mathematica paths: allow backquotes (math-mode ",-:$+<>@-Z_[:lower:]~`" "<" "@>;.,!?`:") ;; (La)TeX: don't allow braces diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el index c7ff175e08..4bcfcb122d 100644 --- a/lisp/net/net-utils.el +++ b/lisp/net/net-utils.el @@ -577,7 +577,7 @@ dns-lookup-host This command uses `dns-lookup-program' for looking up the DNS information." (interactive - (list (let ((default (ffap-machine-at-point))) + (list (let ((default (or (ffap-machine-at-point) (ffap-ip-at-point)))) (read-string (format-prompt "Lookup host" default) nil nil default)) (if current-prefix-arg (read-from-minibuffer "Name server: ")))) (let ((options