ip2country 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +19 -0
  2. data/README +21 -0
  3. data/lib/ip2country.rb +8 -1
  4. metadata +8 -5
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2006 Matthew Harris
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,21 @@
1
+ == Author
2
+ The ip2country library for Ruby was written by Matthew Harris with many
3
+ contributions by the Ruby community.
4
+
5
+ == Synopsis
6
+ This library provides a "IP to country" lookup mechanism for checking remote
7
+ IP addresses against WebHosting.Info ip-to-country database to determine the
8
+ IP's regional origin.
9
+
10
+ == Usage
11
+ require 'rubygems'
12
+ require 'ip2country'
13
+
14
+ ip2c = IP2Country.new
15
+ ip = '58.77.42.37'
16
+
17
+ if country = ip2c.lookup(ip)
18
+ puts "#{ip} belongs is located in: #{country.name} (#{country.cc})"
19
+ else
20
+ puts "The region for #{ip} could not be determined."
21
+ end
data/lib/ip2country.rb CHANGED
@@ -3,7 +3,14 @@ require 'ip2country/country'
3
3
 
4
4
  # IP2Country is used to lookup a host IP from a specified user ip2country database
5
5
  # and determine their regional location.
6
+ #
7
+ # "This script uses the IP-to-Country Database
8
+ # provided by WebHosting.Info (http://www.webhosting.info),
9
+ # available from http://ip-to-country.webhosting.info."
10
+ #
6
11
  class IP2Country
12
+ attr_reader :db_file, :db
13
+
7
14
  # Initialize IP2Country instance using a specified database. If no database is
8
15
  # provided, then it will attempt to use the default one packaged with this
9
16
  # library.
@@ -15,7 +22,7 @@ class IP2Country
15
22
  # Lookup a host IP to figure out their region. If successful, an IP2Country::Country
16
23
  # instance will be returned, else nil.
17
24
  def lookup(ip)
18
- long = ip2long(ip)
25
+ long = ip2long(ip.to_s)
19
26
  result = @db.execute("SELECT country_code2, country_code3, country_name FROM ip2country WHERE ip_from <= #{long} AND ip_to >= #{long}")[0]
20
27
  Country.new(*result) if result
21
28
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ip2country
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
6
+ version: 0.0.2
7
7
  date: 2007-05-01 00:00:00 +09:00
8
8
  summary: IP2Country library for Ruby
9
9
  require_paths:
@@ -34,12 +34,15 @@ files:
34
34
  - lib/ip2country/country.rb
35
35
  - lib/ip2country/ip2country.db
36
36
  - bin/ip2c.updatedb
37
+ - LICENSE
38
+ - README
37
39
  test_files: []
38
40
 
39
- rdoc_options: []
40
-
41
- extra_rdoc_files: []
42
-
41
+ rdoc_options:
42
+ - --main
43
+ - README
44
+ extra_rdoc_files:
45
+ - README
43
46
  executables:
44
47
  - ip2c.updatedb
45
48
  extensions: []