IP转经纬度,经纬度画热力图

1. IP转经纬度

  • 工具:GeoIP python
  • 每个IP一行
  • 代码:
import GeoIP
import sys
import os

def print_usage():
 print "Usage: " + os.path.basename(__file__) + " ipfile.txt"

# make sure we've been passed the filename containing IP addresses
if len(sys.argv) != 2: 
 print_usage()
 sys.exit()

# grab the filename
ipfile = sys.argv[1];

# initialize the GeoIP database
gi = GeoIP.open("GeoLiteCity.dat",GeoIP.GEOIP_STANDARD)

# for each IP in the file...
for line in open(ipfile, "r"):
 # strip newlines
 ip = line.rstrip()

 # look up GeoIP record for this IP
 gir = gi.record_by_name(ip)

 # print lat/long if found in db
 if gir != None:
 	print '{"lng":'+str(gir['longitude'])+',"lat":'+str(gir['latitude'])+',"count":1},'
  • 运行 
python geolite.py ipfile.txt > ip_res.txt

2. 用ip_res.txt的结果替换百度地图API内的经纬度信息

猜你喜欢

转载自blog.csdn.net/jack_ricky/article/details/83415354