<jupyter_start><jupyter_text>Now You Code 2: IP AddressesFor this Now You Code, you will complete a very common task in data analytics: converting an IP address to an approximate location.Write a program to read the IP Addresses from the File `NYC2-IP-Addresses.txt` and for each IP address determine the approximate location (City and State) for the origin of that IP Address. This is usually done as part of analytics to determine the origins of website visitors. To perform the lookups, use the http://freegeoip.net API. You'll have to read through the API documentation first and understand how to use the API before you write the entire program.  As a first step I highly recommed that you get just the IP lookup working, perhaps writing it as a function,  and then try to read from the file and perform the lookups for each IP address in the file.Here's a sample of a geoip lookup of the IP Address `'172.16.58.3'````{'city': 'Syracuse', 'country_code': 'US', 'country_name': 'United States', 'ip': '172.16.58.3', 'latitude': 43.0377, 'longitude': -76.1396, 'metro_code': 555, 'region_code': 'NY', 'region_name': 'New York', 'time_zone': 'America/New_York', 'zip_code': '13244'}```In this example the city and state would be `Syracuse, NY`Final Program Output:```IP: 192.168.127.12 LOCATION: New York,NYIP: 172.16.31.10 LOCATION: Green Bay,WIIP: 172.16.31.10 LOCATION: Cambridge,MAIP: 192.168.3.11 LOCATION: Cheyenne,WYIP: 172.16.17.32 LOCATION: San Jose,CAIP: 172.16.58.3 LOCATION: Phoenix,AZIP: 192.168.127.12 LOCATION: Phoenix,AZIP: 192.168.127.12 LOCATION: Los Angeles,CAIP: 172.16.17.32 LOCATION: Iselin,NJIP: 192.168.3.11 LOCATION: Chicago,ILIP: 172.16.17.32 LOCATION: Orem,UTIP: 172.16.58.3 LOCATION: Matawan,NJIP: 192.168.3.11 LOCATION: Darien,CTIP: 192.168.127.12 LOCATION: Raleigh,NCIP: 172.16.58.3 LOCATION: Elmont,NYIP: 192.168.127.12 LOCATION: Auburn,NYIP: 172.16.58.3 LOCATION: Liverpool,NYIP: 172.16.17.32 LOCATION: Dayton,OH```<jupyter_code># todo write logic (todo list here)
#import requests and json
# function and call the function
#use for loop to iterate
#print
import requests
import json

def load_ip():
    list=[]
    with open ("NYC2-IP-Addresses.txt",'r') as f:
        for line in f:
            list.append(line.strip())
            list.sort()
    return list

ip=load_ip()

url='http://freegeoip.net/json/'
for i in ip:
    response = requests.get(url + i)
    geoip=response.json()
    LOCATION=geoip['city']
    STATE=geoip['region_code']

    print("ip:%s Location: %s %s"%(i,LOCATION,STATE))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12251268045259461, 'fraction_numerical': 0.08076472883339836, 'mean_word_length': 4.502145922746781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 20, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '317379', 'license': 'MIT', 'n_tokens_mistral': 1026, 'n_tokens_neox': 849, 'n_words': 304, 'path': 'content/lessons/11/Now-You-Code/NYC2-Lookup-IP-Addresses.ipynb', 'repo_name': 'yajiao-su/istpytonproject', 'size': '2571'}