Sha256: 9448deaa8573180df9821cac408342823f9dbeefebdea70d53c6bedc4f85667f
Contents?: true
Size: 452 Bytes
Versions: 4
Compression:
Stored size: 452 Bytes
Contents
class Knj::Ip2location def initialize(args = {}) @args = args @http = Knj::Http.new( "host" => "www.ip2location.com", "port" => 80 ) end def lookup(ip) raise "Invalid IP: #{ip}." if !ip.to_s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) html = @http.get("/#{ip}")["data"] ret = {} html.scan(/<span id="dgLookup__ctl2_lblI(.+?)">(.+?)<\/span>/) do |match| ret[match[0]] = match[1] end return ret end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
knjrbfw-0.0.8 | lib/knj/ip2location.rb |
knjrbfw-0.0.7 | lib/knj/ip2location.rb |
knjrbfw-0.0.4 | lib/knj/ip2location.rb |
knjrbfw-0.0.3 | lib/knj/ip2location.rb |