公司内网接口ip城市查询分析

require 'rubygems'
require 'json'
print ARGV 
print "fist is :",ARGV[0]
logfile="#{ARGV[0]}_log"

filex = File.open(logfile, "w+")


File.foreach(ARGV[0]) do |line| 
line = line.gsub("\n", "")
result = `curl -H "APPKEY:xxx" "http://api.bdp.xxxx.com.cn/datacenter/customer/new/api/v1/ipArea/getArea?ipinfo=#{line}"` 
begin
filex << "#{line}:#{JSON.parse(result)["result"]["list"][0]["city"]}"
rescue
filex << "#{line}: #{''}"
end
filex << "\n"
end

统计:

cat log |awk -F":" '{arr[$2]++}END{for(x in arr) print x,arr[x]}' > report.txt

time curl -H "APPKEY:xxxxx" "http://api.bdp.xxxxx.com.cn/datacenter/customer/new/api/v1/ipArea/getArea?ipinfo=27.224.89.214" 
{"message":"ok","result":{"list":[{"province":"甘肃省","city":"甘南藏族自治州","ip":467687894,"cityId":623000,"provinceId":620000}]},"returncode":0}
real 0m0.030s
user 0m0.002s
sys 0m0.002s

powered by xiaorongtao

 

posted on 2019-04-22 10:50  iokde.com  阅读(223)  评论(0编辑  收藏  举报

导航