Created
April 30, 2012 11:57
-
-
Save tlatsas/2557638 to your computer and use it in GitHub Desktop.
pentadactyl - get ip address function
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
function ip() { | |
var req = new XMLHttpRequest(); | |
req.open('GET', 'http://checkip.dyndns.org/', true); | |
req.onreadystatechange = function (ev) { | |
if (req.readyState == 4) { | |
var ip_re = /[0-9]+.[0-9]+.[0-9]+.[0-9]+/g; | |
try { | |
dactyl.echo(req.responseText.match(ip_re)[0]); | |
} | |
catch (err) { | |
dactyl.echo(err); | |
} | |
} | |
} | |
req.send(null); | |
} | |
/* | |
* map in pentadactyl with: | |
* command ip -js ip() | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment