Created
February 22, 2011 22:23
-
-
Save chmouel/839558 to your computer and use it in GitHub Desktop.
Get your current IP in Emacs Lisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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