def get_ip():
    group = re.compile('(?P<ip>\\d+\\.\\d+\\.\\d+\\.\\d+)').search(urllib.request.
        URLopener().open('http://jsonip.com/').read()).groupdict()
return group['ip']
How do I get the external IP of a socket in Python?