Skip to content

Instantly share code, notes, and snippets.

@cjlano
Last active August 29, 2015 13:55
Show Gist options
  • Save cjlano/8692137 to your computer and use it in GitHub Desktop.
Save cjlano/8692137 to your computer and use it in GitHub Desktop.
# DuckDuckGo (sudo pip install duckduckgo)
>>> import duckduckgo
>>> r = duckduckgo.query("ip address")
>>> r.answer.text
'Your IP address is ...'
>>> import re
>>> address_regexp = re.compile ('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
>>> result = address_regexp.search( r.answer.text )
>>> result.group()
'xx.xx.xx.xxx'
# DynDNS
>>> import urllib2
>>> ip_checker_url = "http://checkip.dyndns.org/"
>>> response = urllib2.urlopen(ip_checker_url).read()
>>> result = address_regexp.search(response)
>>> result.group()
'xx.xx.xx.xxx'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment