ip2l 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +39 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/ip2l +37 -0
- data/bin/setup +7 -0
- data/ip2l.gemspec +23 -0
- data/lib/ip2l.rb +14 -0
- data/lib/ip2l/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 27d045474b15721b9b74e1c2d828f5c95dc35863
|
|
4
|
+
data.tar.gz: 732fa3ed8761c738aaf660c27f8323f833413dd5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 582bcf2de02bd707db022fca24f64afbdc66c27386c302aa046ebfb920986742dda32c74911167720ecb59506c1b981aa5683c03f1b3b03accaabeff07f1726e
|
|
7
|
+
data.tar.gz: d778aa53608ccd0f50dd34f487fb74aab57c0ad150e074120240db4ef9dceb1abf2740aad808fba63f96c9b353b616de8972b674b43ee3d9cc59c91cf2b78bc2
|
data/.gitignore
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Created by https://www.gitignore.io
|
|
2
|
+
|
|
3
|
+
### Ruby ###
|
|
4
|
+
*.gem
|
|
5
|
+
*.rbc
|
|
6
|
+
/.config
|
|
7
|
+
/coverage/
|
|
8
|
+
/InstalledFiles
|
|
9
|
+
/pkg/
|
|
10
|
+
/spec/reports/
|
|
11
|
+
/test/tmp/
|
|
12
|
+
/test/version_tmp/
|
|
13
|
+
/tmp/
|
|
14
|
+
|
|
15
|
+
## Specific to RubyMotion:
|
|
16
|
+
.dat*
|
|
17
|
+
.repl_history
|
|
18
|
+
build/
|
|
19
|
+
|
|
20
|
+
## Documentation cache and generated files:
|
|
21
|
+
/.yardoc/
|
|
22
|
+
/_yardoc/
|
|
23
|
+
/doc/
|
|
24
|
+
/rdoc/
|
|
25
|
+
|
|
26
|
+
## Environment normalisation:
|
|
27
|
+
/.bundle/
|
|
28
|
+
/vendor/bundle
|
|
29
|
+
/lib/bundler/man/
|
|
30
|
+
|
|
31
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
32
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
33
|
+
# Gemfile.lock
|
|
34
|
+
# .ruby-version
|
|
35
|
+
# .ruby-gemset
|
|
36
|
+
|
|
37
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
38
|
+
.rvmrc
|
|
39
|
+
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# IP2Location
|
|
2
|
+
|
|
3
|
+
Reverse geocoding from ip address via an HTTP request.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'ip2l'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install ip2l
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
ip2l <IP>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
ip2l 2.22.61.217
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
36
|
+
|
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/JohnWong/ip2location.
|
|
42
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "ip2l"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/ip2l
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'Ip2l'
|
|
5
|
+
|
|
6
|
+
optparse = OptionParser.new do |opts|
|
|
7
|
+
opts.banner = "Reverse geocoding from ip address via an HTTP request."
|
|
8
|
+
opts.separator ""
|
|
9
|
+
opts.separator " Usage:"
|
|
10
|
+
opts.separator " ip2l <IP>"
|
|
11
|
+
opts.separator ""
|
|
12
|
+
opts.separator " Example:"
|
|
13
|
+
opts.separator " ip2l 2.22.61.217"
|
|
14
|
+
opts.separator ""
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
begin
|
|
19
|
+
options = optparse.parse!
|
|
20
|
+
if options.count == 0
|
|
21
|
+
puts "Missing argument: IP"
|
|
22
|
+
puts optparse
|
|
23
|
+
exit
|
|
24
|
+
elsif options.count > 1
|
|
25
|
+
puts "Too many arguments"
|
|
26
|
+
puts optparse
|
|
27
|
+
exit
|
|
28
|
+
end
|
|
29
|
+
ip = options[0]
|
|
30
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
|
31
|
+
puts $!.to_s
|
|
32
|
+
puts optparse
|
|
33
|
+
exit
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
ip2l = Ip2l::Ip2l.new
|
|
37
|
+
puts ip2l.ip_to_location(ip)
|
data/bin/setup
ADDED
data/ip2l.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'ip2l/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "ip2l"
|
|
8
|
+
spec.version = Ip2l::VERSION
|
|
9
|
+
spec.authors = ["John Wong"]
|
|
10
|
+
spec.email = ["huangxiaozhe1988@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Reverse geocoding from ip address via an HTTP request."
|
|
13
|
+
spec.description = "Reverse geocoding from ip address via an HTTP request."
|
|
14
|
+
spec.homepage = "https://github.com/JohnWong/ip2location"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
17
|
+
spec.bindir = "bin"
|
|
18
|
+
spec.executables = ["ip2l"]
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
+
end
|
data/lib/ip2l.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "ip2l/version"
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Ip2l
|
|
6
|
+
class Ip2l
|
|
7
|
+
def ip_to_location(ip)
|
|
8
|
+
uri = URI("http://pytool.sinaapp.com/geo?type=json&pos=1&encoding=utf-8&ip=%s" % ip)
|
|
9
|
+
content = Net::HTTP.get(uri)
|
|
10
|
+
result = JSON.parse(content)
|
|
11
|
+
result["geo"]["loc"]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/ip2l/version.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ip2l
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- John Wong
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.10'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.10'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: Reverse geocoding from ip address via an HTTP request.
|
|
42
|
+
email:
|
|
43
|
+
- huangxiaozhe1988@gmail.com
|
|
44
|
+
executables:
|
|
45
|
+
- ip2l
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- bin/console
|
|
54
|
+
- bin/ip2l
|
|
55
|
+
- bin/setup
|
|
56
|
+
- ip2l.gemspec
|
|
57
|
+
- lib/ip2l.rb
|
|
58
|
+
- lib/ip2l/version.rb
|
|
59
|
+
homepage: https://github.com/JohnWong/ip2location
|
|
60
|
+
licenses: []
|
|
61
|
+
metadata: {}
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubyforge_project:
|
|
78
|
+
rubygems_version: 2.4.8
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 4
|
|
81
|
+
summary: Reverse geocoding from ip address via an HTTP request.
|
|
82
|
+
test_files: []
|