Question: Now You Code 2: IP Addresses For this Now You Code, you will complete a very common task in data analytics: converting an IP address

Now You Code 2: IP Addresses

For 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 '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:

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 

Please help me with this Python program usin API's. How exactly do I use http://freegeoip.net API in my program?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!