Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Created April 29, 2015 18:59
Show Gist options
  • Save ba0f3/0ba4068dec5c9535621b to your computer and use it in GitHub Desktop.
Save ba0f3/0ba4068dec5c9535621b to your computer and use it in GitHub Desktop.
Get external IP and display it to stdout
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