import requests
import json


def get_ipaddr(url='http://httpbin.org/ip', proxy=None):
    """ gets the external IP address """

    if proxy:
        proxy = 'http://{0}'.format(proxy)
        proxies = {'http': proxy, 'https': proxy}
        response = requests.get(url, proxies=proxies)
    else:
        response = requests.get(url)

    if response.status_code == 200:
        try:
            return json.loads(response.content.decode('utf-8'))['origin']
        except json.decoder.JSONDecodeError:
            return None
    return None