Skip to content

Commit f3c02c0

Browse files
committed
Release v0.0.1
1 parent d8367e7 commit f3c02c0

File tree

14 files changed

+212
-6
lines changed

14 files changed

+212
-6
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ build/
2727

2828
# for a library or gem, you might want to ignore these files since the code is
2929
# intended to run in multiple environments; otherwise, check them in:
30-
# Gemfile.lock
31-
# .ruby-version
32-
# .ruby-gemset
30+
Gemfile.lock
31+
.ruby-version
32+
.ruby-gemset
3333

3434
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3535
.rvmrc
36+
37+
.DS_Store

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: ruby
2+
3+
rvm:
4+
- 1.9.2
5+
- 2.1.6
6+
- 2.2.2

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## IPIP Changelog
2+
3+
#### v0.0.1 [2015-09-27]
4+
5+
- Release first version.

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
3+
gemspec

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
1-
# ipip
2-
IP search based on IPIP.net
1+
# IPIP
2+
3+
[![Gem Version](https://badge.fury.io/rb/ipip.svg)](http://badge.fury.io/rb/ipip)
4+
[![Build Status](https://travis-ci.org/liluo/ipip.svg?branch=master)](https://travis-ci.org/liluo/ipip)
5+
6+
IP search based on [IPIP.net](http://ipip.net/)
7+
8+
### Getting Started
9+
10+
Install the gem:
11+
12+
```
13+
gem install ipip
14+
```
15+
16+
Then use it in your application:
17+
18+
```
19+
require 'ipip'
20+
21+
# => Format: "国家\t省份或直辖市\t地区或城市\t学校或单位"
22+
23+
IPIP.find('127.0.0.1') # => "本机地址\t本机地址\t\t"
24+
25+
IPIP.find('211.147.4.49') # => "中国\t北京\t北京\t"
26+
27+
IPIP.find('202.195.161.30') # => "中国\t江苏\t镇江\t江苏大学"
28+
29+
IPIP.find('www.douban.com') # => "中国\t北京\t北京\t"
30+
```
31+
32+
You can try running `ipip [ip | domain]`:
33+
34+
```
35+
$ ipip 202.195.161.30
36+
Location for 202.195.161.30: 中国 江苏 镇江 江苏大学
37+
38+
$ ipip douban.com
39+
Location for douban.com: 中国 北京 北京
40+
```
41+
42+
### Contributing
43+
44+
* Fork the repository.
45+
* Create a topic branch.
46+
* Implement your feature or bug fix.
47+
* Add, commit, and push your changes.
48+
* Submit a pull request.
49+
50+
### ChangeLog
51+
52+
[ChangeLog](CHANGES.md)
53+
54+
### License
55+
56+
Released under the [MIT license](LICENSE).

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "rspec/core/rake_task"
2+
3+
RSpec::Core::RakeTask.new(:spec)
4+
5+
task default: :spec

bin/ipip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
3+
# ipip - IP location search based on ipip.net.
4+
# usage: ipip [ip | domain]
5+
#
6+
7+
require 'socket'
8+
require 'ipip'
9+
10+
if ip = ARGV[0]
11+
location = IPIP.find(ip)
12+
puts "Location for #{ip}: #{location}"
13+
else
14+
abort "usage: ipip [ip | domain]"
15+
end

ipip.gemspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ Gem::Specification.new do |gem|
1111
gem.summary = %q{ IP search based on ipip.net }
1212

1313
gem.files = Dir['lib/**/*']
14+
gem.executables = ['ipip']
15+
16+
gem.add_development_dependency 'rake'
17+
gem.add_development_dependency 'rspec'
1418
end

lib/ipip.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
require 'ipip/version'
2+
require 'ipip/ipv4_database'
23

34
module IPIP
5+
6+
class << IPIP
7+
8+
def find(ip)
9+
ipv4_database.find(ip)
10+
end
11+
12+
def ipv4_database(data_file=nil)
13+
@ipv4_database ||= IPv4Database.new(data_file)
14+
end
15+
16+
end
17+
418
end

lib/ipip/17monipdb.dat

1.61 MB
Binary file not shown.

0 commit comments

Comments
 (0)