[英]Coverting Batch IP Addresses to Find Location
是否有任何服務可以讓我確定 1000 多個 IP 地址的位置? 我遇到的服務將其限制為 20、40、50 或 100 個 IP 地址。 這是可以用 Python 編程的東西嗎? 我在 JavaScript/Python 方面的經驗很少。 不確定是否有 API 或服務可以讓我檢索這些信息。 我聽說過GeoIP ,但不知道從哪里開始。
謝謝。
您可以使用這個免費的在線 ip 位置批量查找工具。 據我所知,沒有限制。 只需復制並粘貼您的列表。 可能需要等待一段時間才能通過您的列表。
我剛剛寫了一個腳本來處理這個問題。
這是來源:
import csv
import requests
def get_addresses(filename):
"""
Given a CSV file, this function returns a list of lists
where each element (list) in the outer list contains the
row info from the csv file.
"""
all_addresses = []
with open(filename, 'rb') as f:
reader = csv.reader(f)
for row in reader:
all_addresses.append(row)
return all_addresses
def get_geolocation(all_the_ip_address):
"""
Given a list of lists from `get_addresses()`, this function
returns an updated lists of lists containing the geolocation.
"""
print("Getting geo information...")
updated_addresses = []
counter = 1
# update header
header_row = all_the_ip_address.pop(0)
header_row.extend(['Country', 'City'])
# get geolocation
for line in all_the_ip_address:
print "Grabbing geo info for row # {0}".format(counter)
r = requests.get('https://reallyfreegeoip.org/json/{0}'.format(line[0]))
line.extend([str(r.json()['country_name']), str(r.json()['city'])])
updated_addresses.append(line)
counter += 1
updated_addresses.insert(0, header_row)
return updated_addresses
def create_csv(updated_address_list):
"""
Given the updated lists of lists from `get_geolocation()`, this function
creates a new CSV.
"""
with open('output.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerows(updated_address_list)
print "All done!"
if __name__ == '__main__':
csv_file = '25_sample_csv.csv'
all_the_ip_address = get_addresses(csv_file)
updated_address_list = get_geolocation(all_the_ip_address)
create_csv(updated_address_list)
希望有幫助。
免費數據庫: http : //dev.maxmind.com/geoip/geoip2/geolite2/
這些 API: http : //dev.maxmind.com/geoip/geoip2/downloadable/#MaxMind_APIs
使用 Python API 用 Python 編寫腳本,查詢每個 IP 地址的 API,然后記錄結果。
我推薦使用blockfinder,因為它可以從 IP 注冊商那里獲取信息。 我見過的每個 GeoIP 提供商幾乎都有相同的數據,除非它們有真正的數據倉庫支持(比普通人能負擔得起的更貴,想想:“信用卡公司”)。
是的,授予 IP 可能不在確切的省份,但您至少可以按國家/地區縮小范圍,這對大多數人來說可能已經足夠了。
警告的話,上次我看到只有blockfinder命令實用程序-我什至不知道它們是否公開了API。 但是,它是用 Python 編寫的。
ipapi.co
了一個批量 IP 地址查找工具,可用於將一千個左右的 IP 地址轉換為位置。
它既可以通過 Web 界面使用,也可以作為可以從 Python / Javascript / PHP 等調用的 API 使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.