是否有任何服务可以让我确定1000多个IP地址的位置?我遇到的服务将其限制为20、40、50或100个IP地址。这是可以用Python编程的东西吗?我在JavaScript/Python方面有很小的经验。不确定是否有API或服务可以让我检索这些信息。我听说过GeoIP,但不知道从哪里开始。
谢谢。
您可以使用这个免费的在线ip位置批量查找工具。据我所知,没有限制。只需复制并粘贴您的列表。可能需要等待一段时间才能通过您的列表。
https://reallyfreegeoip.org/bulk
我刚刚写了一个脚本来处理这个问题。
以下是来源:
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提供商都有相同的数据,除非他们有真正的数据仓库支持(比普通人能负担得起的更贵,想想:"信用卡公司")。
是的,当然知识产权可能不在确切的省份,但你至少可以按国家缩小范围,这对大多数人来说可能已经足够了。
警告一下,上次我看的时候只有blockfinder命令实用程序——我甚至不知道他们是否公开了API。但是,它是用Python编写的。
ipapi.co
中有一个批量IP地址查找工具,您可以使用它将大约1000个IP地址转换为位置。
它既可以通过web界面使用,也可以作为API从Python/Javascript/PHP等调用。