Skip to content

Instantly share code, notes, and snippets.

@psachin
Created May 22, 2014 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psachin/906598dd223956260710 to your computer and use it in GitHub Desktop.
Save psachin/906598dd223956260710 to your computer and use it in GitHub Desktop.
Get IP-address of device.
;; get IP-address of host or remote
;; Ref: EMACS-FU ==> Programming. by: Eric Ludlam
(defun get-ip-address (&optional dev)
"Get the IP-address for device DEV (default: eth0)"
(interactive)
(let ((dev (if dev dev "eth0")))
(substring ;; chop the final "\n"
(shell-command-to-string
(concat
"ifconfig " dev
"|grep 'inet addr'|sed 's/.*inet addr:\\(\\([0-9\.]\\)*\\).*/\\1/'"))
0 -1)))
(get-ip-address "eth0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment