公司内网接口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":,"cityId":,"provinceId":}]},"returncode":}
real 0m0.030s
user 0m0.002s
sys 0m0.002s

powered by xiaorongtao

上一篇:HDU 5919 -- Sequence II (主席树)


下一篇:HDU 5919 Sequence II 主席树