commit 094dcade4bd3a02ebb1c836c021c52e097321dbe Author: Ana Custura ana@netstat.org.uk Date: Wed Mar 6 14:37:14 2019 +0100
Documents find_ip_address_local() and fixes its return type --- onionperf/util.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/onionperf/util.py b/onionperf/util.py index f49fb30..84fb58a 100644 --- a/onionperf/util.py +++ b/onionperf/util.py @@ -114,7 +114,16 @@ def do_dates_match(date1, date2): return False
def find_ip_address_url(data): - ip_address = None + """ + Parses a string using a regular expression for identifying IPv4 addressses. + If more than one IP address is found, only the first one is returned. + If no IP address is found, the function returns an empty string. + + :param data: string + :returns: string + """ + + ip_address = "" if data is not None and len(data) > 0: ip_list = re.findall(r'[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.[\d]{1,3}', data) if ip_list is not None and len(ip_list) > 0: @@ -141,7 +150,7 @@ def get_ip_address(): try: data = urllib.urlopen('https://check.torproject.org/%27).read() ip_address = find_ip_address_url(data) - if ip_address is None: + if not ip_address: logging.error( "Unable to determine IP address from check.torproject.org. " "The site was successfully contacted but the result could "