al-net.el 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;; al-net.el --- Additional functionality for network stuff (including `net-utils' package)
  2. ;; Copyright © 2013-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (defcustom al/net-hosts
  15. '("google.com" "ya.ru")
  16. "List of hosts to choose from for `al/ping' command."
  17. :group 'net-utils
  18. :type '(repeat string))
  19. ;;;###autoload
  20. (defun al/ping (host)
  21. "Ping HOST.
  22. Same as `ping' but interactively complete hosts from `al/net-hosts'."
  23. (interactive
  24. (list (ido-completing-read "Ping host: " al/net-hosts)))
  25. (ping host))
  26. ;;;###autoload
  27. (defun al/traceroute (host)
  28. "Traceroute HOST.
  29. Same as `traceroute' but interactively complete hosts from `al/net-hosts'."
  30. (interactive
  31. (list (ido-completing-read "Traceroute host: " al/net-hosts)))
  32. (traceroute host))
  33. ;;; Router log
  34. (defvar al/router-log-path "~/.router-log"
  35. "Directory with router log-files.")
  36. (defvar al/router-log-format "%Y-%m-%d_%H:%M.log"
  37. "Format used for the names of saved router log-files.
  38. This variable is passed to `format-time-string' with current time.")
  39. (defvar al/router-log-url "http://192.168.1.1/cgi-bin/ExportSyslog.sh"
  40. "URL with router log.")
  41. (defvar url-handler-regexp)
  42. (declare-function syslog-mode "syslog-mode")
  43. ;;;###autoload
  44. (defun al/router-get-log ()
  45. "Show a buffer with router log."
  46. (interactive)
  47. (require 'url-handlers)
  48. (let ((file-name-handler-alist
  49. (cons (cons url-handler-regexp 'url-file-handler)
  50. file-name-handler-alist)))
  51. (find-file-literally al/router-log-url)
  52. (syslog-mode)))
  53. (defun al/router-save-log ()
  54. "Save current buffer as router log."
  55. (interactive)
  56. (write-file
  57. (expand-file-name (format-time-string al/router-log-format
  58. (current-time))
  59. al/router-log-path)))
  60. (provide 'al-net)
  61. ;;; al-net.el ends here