--- tags: Project --- # GeoIP RESTFul API Data Source: Maxmind Free Data (CSV) 1. Convert data to json 2. Process data to SQL **(PostgreSQL)** 3. RESTFul Data **(Golang)** ## Current Issue Maxmind Free Data Location and ASN Block Network Cidr are different ## Idea Get ASN from BGP Full Table ## SQL Table Field - Network Cidr - Country Code (Ex: TW) - Country - ASN - ASN Organization - Time Zone ## Demo ## Source Code **import to SQL from json** by Python ```bash import json GeoIP_Data = json.load(open('json\GeoLite2-ASN-Blocks-IPv4.json')) Location_Data = json.load(open('json\GeoLite2-Country-Blocks-IPv4.json')) Country_Location_Data = json.load(open('json\GeoLite2-Country-Locations-en.json', encoding="utf-8")) # Process Location def location(network): Location_data = Location_Data for i in Location_data: if i['network'] == network: id = (i['geoname_id']) return (country_name(id)) # Get Country Code def country_name(id): for i in Country_Location_Data: if i['geoname_id'] == id: country_code = (i['country_iso_code']) return country_code # Process Network Cidr a = "0" num = 0 while a != "": geoip_data = GeoIP_Data[num]['network'] num += 1 print(geoip_data) print(location(geoip_data)) ```