Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created February 22, 2011 22:23
Show Gist options
  • Select an option

  • Save chmouel/839558 to your computer and use it in GitHub Desktop.

Select an option

Save chmouel/839558 to your computer and use it in GitHub Desktop.
Get your current IP in Emacs Lisp
(defun get-ip (interface)
(save-excursion
(with-temp-buffer
(call-process "/sbin/ifconfig" nil t nil "-a")
(goto-char (point-min))
(when (re-search-forward interface nil t)
(case system-type
(gnu/linux (re-search-forward "inet addr:\\([^ ]*\\)"))
(darwin (re-search-forward "inet \\([^ ]*\\)" nil t)))
(buffer-substring (match-beginning 1)
(match-end 1)))
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment