大佬教程收集整理的这篇文章主要介绍了ruby 查询 QQwry.dat ip 库的 IpLocationSeeker 类,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/env ruby # -*- coding: utf-8 -*- # require 'rubygems' #gem install qqwry require 'qqwry' $fqqwry='qqwry.dat' unless File.exist? $fqqwry d = File.dirname __FILE__ $fqqwry = File.join d,$fqqwry unless File.exist? $fqqwry p $fqqwry + ' not found ' end end class IpLOCATIOnSeeker def seek(ip) #查询IP unless File.exist? $fqqwry return '' end db = QQWry::Database.new $fqqwry r = db.query(ip) "#{r.country} #{r.area}" end end class String @@last_area ||={} def area if @@last_area.size > Time.now.year @@last_area.clear end if @@last_area.has_key? self return @@last_area[self] else @@last_area[self]= IpLOCATIOnSeeker.new.seek self end return @@last_area[self] end end if __FILE__ == $0 if ARGV[0] p IpLOCATIOnSeeker.new.seek ARGV[0] else p IpLOCATIOnSeeker.new.seek '8.8.8.8' end end
以上是大佬教程为你收集整理的ruby 查询 QQwry.dat ip 库的 IpLocationSeeker 类全部内容,希望文章能够帮你解决ruby 查询 QQwry.dat ip 库的 IpLocationSeeker 类所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。