Created
April 29, 2015 18:59
-
-
Save ba0f3/0ba4068dec5c9535621b to your computer and use it in GitHub Desktop.
Get external IP and display it to stdout
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
import httpclient, re | |
proc subString(s: string, start: int, stop: int): string = | |
return s[start..stop] | |
var resp: string = "" | |
try: | |
resp = getContent("http://checkip.dyndns.org") | |
except ProtocolError: | |
quit("Error") | |
var start = find(resp, re"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})") | |
if start != -1: | |
var stop = find(resp, re"<\/body>") | |
echo (resp.subString(start, stop-1)) | |
else: | |
echo "Unknown" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment