ip_reverse 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +9 -0
- data/ip_reverse.gemspec +20 -0
- data/lib/ip_reverse/version.rb +3 -0
- data/lib/ip_reverse.rb +27 -0
- data/test/test_ip_reverse.rb +35 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 chad_lwm
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# IP Reverse
|
2
|
+
|
3
|
+
IP address reverse, only for ipv4.
|
4
|
+
|
5
|
+
Keep it simple, stupid
|
6
|
+
|
7
|
+
The reverse result display as hash object, containing `country`, `province`, `city`, `county`, `isp`, `area`
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'ip_reverse'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ip_reverse
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
ip_reverse = IpReverse.reverse("182.48.112.2")
|
26
|
+
|
27
|
+
#{"result"=>"success", "country"=>"中国", "province"=>"北京市", "city"=>"北京市", "county"=>"海淀区", "isp"=>"", "area"=>"华北"}
|
28
|
+
|
29
|
+
ip_reverse = IPReverse.reverse("119.178.225.92")
|
30
|
+
ip_reverse['result'] # success or failed
|
31
|
+
ip_reverse['message'] # if result is failed, this will give details info
|
32
|
+
ip_reverse['country'] # => 国家:"中国"
|
33
|
+
ip_reverse['province'] # => 省份:"山东省"
|
34
|
+
ip_reverse['city'] # => 城市:"菏泽市"
|
35
|
+
ip_reverse['county'] # => 县:""
|
36
|
+
ip_reverse['isp'] # => 运营商:"联通"
|
37
|
+
ip_reverse['area'] # => 地区:"华东"
|
38
|
+
|
39
|
+
## Accuracy & Coverage
|
40
|
+
|地区|覆盖度|准确度|
|
41
|
+
| -------- | ------------------- | ---------------------|
|
42
|
+
| 国家| 100% | 100% |
|
43
|
+
| 省/直辖市/自治区 | 99.83% | 99.88% |
|
44
|
+
| 市 | 93.68% | 96.35% |
|
45
|
+
| 县 | 4.64% | 无统计数据 |
|
46
|
+
| 运营商 | 94.1% | 无统计数据 |
|
47
|
+
|
48
|
+
## Run Test
|
49
|
+
|
50
|
+
rake test
|
51
|
+
|
52
|
+
## Contact
|
53
|
+
|
54
|
+
Name
|
55
|
+
: chad lwm
|
56
|
+
|
57
|
+
Mail
|
58
|
+
: [chad_lwm@hotmail.com](mailto:chad_lwm@hotmail.com)
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ip_reverse.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ip_reverse/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ip_reverse"
|
8
|
+
gem.version = IpReverse::VERSION
|
9
|
+
gem.authors = ["chad_lwm"]
|
10
|
+
gem.email = ["chad_lwm@hotmail.com"]
|
11
|
+
gem.description = %q{ip address reverse}
|
12
|
+
gem.summary = %q{ip address reverse, keep it simple, stupid}
|
13
|
+
gem.homepage = "https://github.com/chadlwm/ip_reverse"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_runtime_dependency "rest-client"
|
20
|
+
end
|
data/lib/ip_reverse.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "ip_reverse/version"
|
2
|
+
require 'rest-client'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module IpReverse
|
6
|
+
class << self
|
7
|
+
def reverse(ip)
|
8
|
+
response = RestClient.get "http://ip.taobao.com/service/getIpInfo.php?ip=#{ip}"
|
9
|
+
ip_reverse = JSON.parse(response)
|
10
|
+
result = {}
|
11
|
+
result["result"] = ip_reverse["code"] == 0 ? "success" : "failed"
|
12
|
+
|
13
|
+
if result["result"] == "failed"
|
14
|
+
result["message"] = ip_reverse["data"]
|
15
|
+
else
|
16
|
+
data = ip_reverse["data"]
|
17
|
+
result["country"] = data["country"]
|
18
|
+
result["province"]= data["region"]
|
19
|
+
result["city"] = data["city"]
|
20
|
+
result["county"] = data["county"]
|
21
|
+
result["isp"] = data["isp"]
|
22
|
+
result["area"] = data["area"]
|
23
|
+
end
|
24
|
+
result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'ip_reverse'
|
4
|
+
|
5
|
+
class IpReverseTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_ip_reverse_success
|
8
|
+
ip_reverse = IpReverse.reverse("119.178.225.92")
|
9
|
+
p ip_reverse
|
10
|
+
assert_equal ip_reverse['result'] , "success"
|
11
|
+
assert_equal ip_reverse['country'] , "中国" # => 国家/地区
|
12
|
+
assert_equal ip_reverse['province'] , "山东省" # => 省份
|
13
|
+
assert_equal ip_reverse['city'] , "菏泽市" # => 城市
|
14
|
+
assert_equal ip_reverse['county'] , "" # => 县
|
15
|
+
assert_equal ip_reverse['isp'] , "联通" # => 运营商
|
16
|
+
assert_equal ip_reverse['area'] , "华东" # =>
|
17
|
+
|
18
|
+
ip_reverse = IpReverse.reverse("182.48.112.2")
|
19
|
+
p ip_reverse
|
20
|
+
assert_equal ip_reverse['result'] , "success"
|
21
|
+
assert_equal ip_reverse['country'] , "中国" # => 国家/地区
|
22
|
+
assert_equal ip_reverse['province'] , "北京市" # => 省份
|
23
|
+
assert_equal ip_reverse['city'] , "北京市" # => 城市
|
24
|
+
assert_equal ip_reverse['county'] , "海淀区" # => 县
|
25
|
+
assert_equal ip_reverse['isp'] , "" # => 运营商
|
26
|
+
assert_equal ip_reverse['area'] , "华北" # =>
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_ip_reverse_failed_with_invalid_ip
|
30
|
+
ip_reverse = IpReverse.reverse("1234.5678.9abc.def0")
|
31
|
+
p ip_reverse
|
32
|
+
assert_equal ip_reverse['result'] , "failed"
|
33
|
+
assert_equal ip_reverse['message'] , "invaild ip." # => details info
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ip_reverse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- chad_lwm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ip address reverse
|
31
|
+
email:
|
32
|
+
- chad_lwm@hotmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- ip_reverse.gemspec
|
43
|
+
- lib/ip_reverse.rb
|
44
|
+
- lib/ip_reverse/version.rb
|
45
|
+
- test/test_ip_reverse.rb
|
46
|
+
homepage: https://github.com/chadlwm/ip_reverse
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: ip address reverse, keep it simple, stupid
|
70
|
+
test_files:
|
71
|
+
- test/test_ip_reverse.rb
|