For this Now You Code, you will complete a very common task in data analytics: converting an IP address https://en.wikipedia.org/wiki/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://api.ipstack.com API. You'll have to read through the API documentation first and understand how to use the API before you write the program.
Once again, problem simplification is key here. Just get the IP lookup working, 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 '128.230.182.217'
{'city': 'Syracuse',
'country_code': 'US',
'country_name': 'United States',
'ip': '128.230.182.217',
'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 will read all the addresses from the file.:
IP: 128.122.140.238 LOCATION: New York,NY
IP: 23.112.232.160 LOCATION: Green Bay,WI
IP: 23.192.215.44 LOCATION: Cambridge,MA
IP: 23.224.160.4 LOCATION: Cheyenne,WY
IP: 23.230.12.5 LOCATION: San Jose,CA
IP: 23.80.125.101 LOCATION: Phoenix,AZ
IP: 23.83.132.200 LOCATION: Phoenix,AZ
IP: 23.88.15.5 LOCATION: Los Angeles,CA
IP: 24.0.14.56 LOCATION: Iselin,NJ
IP: 24.1.25.140 LOCATION: Chicago,IL
IP: 24.11.125.10 LOCATION: Orem,UT
IP: 24.38.114.105 LOCATION: Matawan,NJ
IP: 24.38.224.161 LOCATION: Darien,CT
IP: 56.216.127.219 LOCATION: Raleigh,NC
IP: 68.199.40.156 LOCATION: Elmont,NY
IP: 74.111.18.59 LOCATION: Auburn,NY
IP: 74.111.6.173 LOCATION: Liverpool,NY
IP: 98.29.25.44 LOCATION: Dayton,OH
In [ ]:
# Step 2: write the user defined function `geoiplookup`
In [ ]:
# Step 2.b Tests for geoip lookup help ensure you wrote the function correctly!
print("WHEN ip='128.230.12.5' We EXPECT geoiplookup(ip) to return city Syracuse ACTUAL:", geoiplookup('128.230.12.5')['city'])
print("WHEN ip='www.syracuse.edu' We EXPECT geoiplookup(ip) to return city Syracuse ACTUAL:", geoiplookup('www.syracuse.edu')['city'])
In [ ]:
# Step 4: write main program here
Answer:
Answer:
Answer:
Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?
To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.
Keep your response to between 100 and 250 words.
--== Write Your Reflection Below Here ==--