wosmvp-ipparse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +38 -0
- data/Rakefile +13 -0
- data/bin/ipparse +13 -0
- data/data/116.txt +1069 -0
- data/data/117.txt +496 -0
- data/data/118.txt +308 -0
- data/data/119.txt +414 -0
- data/data/121.txt +1380 -0
- data/data/122.txt +753 -0
- data/data/123.txt +1019 -0
- data/data/124.txt +1573 -0
- data/data/125.txt +1402 -0
- data/data/192.txt +1354 -0
- data/data/193.txt +1094 -0
- data/data/194.txt +5067 -0
- data/data/195.txt +5773 -0
- data/data/202.txt +4787 -0
- data/data/203.txt +1393 -0
- data/data/210.txt +2372 -0
- data/data/211.txt +4044 -0
- data/data/212.txt +3113 -0
- data/data/213.txt +1245 -0
- data/data/217.txt +1015 -0
- data/data/218.txt +25239 -0
- data/data/219.txt +7887 -0
- data/data/220.txt +0 -0
- data/data/221.txt +7406 -0
- data/data/222.txt +9954 -0
- data/data/58.txt +2360 -0
- data/data/59.txt +0 -0
- data/data/60.txt +2968 -0
- data/data/61.txt +15854 -0
- data/data/62.txt +1490 -0
- data/data/80.txt +758 -0
- data/data/81.txt +550 -0
- data/ipparse.gemspec +34 -0
- data/lib/ipparse.rb +25 -0
- data/lib/version.rb +3 -0
- data/test/test_ipparse.rb +15 -0
- metadata +98 -0
data/ipparse.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ipparse}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Zhang Jinzhu"]
|
9
|
+
s.date = %q{2009-02-16}
|
10
|
+
s.default_executable = %q{ipparse}
|
11
|
+
s.description = %q{IP Parse}
|
12
|
+
s.email = %q{wosmvp@gmail.com}
|
13
|
+
s.executables = ["ipparse"]
|
14
|
+
s.extra_rdoc_files = ["lib/ipparse.rb", "lib/version.rb", "bin/ipparse"]
|
15
|
+
s.files = ["test/test_ipparse.rb", "data/203.txt", "data/195.txt", "data/213.txt", "data/81.txt", "data/194.txt", "data/217.txt", "data/80.txt", "data/118.txt", "data/117.txt", "data/212.txt", "data/222.txt", "data/210.txt", "data/116.txt", "data/122.txt", "data/124.txt", "data/119.txt", "data/123.txt", "data/59.txt", "data/60.txt", "data/58.txt", "data/121.txt", "data/193.txt", "data/219.txt", "data/221.txt", "data/192.txt", "data/202.txt", "data/125.txt", "data/211.txt", "data/61.txt", "data/62.txt", "data/218.txt", "data/220.txt", "lib/ipparse.rb", "lib/version.rb", "Rakefile", "bin/ipparse", "Manifest", "ipparse.gemspec"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://www.zhangjinzhu.com}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ipparse", "--main", "README"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{ipparse}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{IP Parse}
|
23
|
+
s.test_files = ["test/test_ipparse.rb"]
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 2
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
else
|
31
|
+
end
|
32
|
+
else
|
33
|
+
end
|
34
|
+
end
|
data/lib/ipparse.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# IPV4
|
2
|
+
class IPParse
|
3
|
+
def self.parse(ip)
|
4
|
+
return false unless ip.to_s =~ /(\d+\.){3}\d+/
|
5
|
+
ip,addr = format(ip) , ''
|
6
|
+
|
7
|
+
[ip.split('.')[0],'0'].each do |f|
|
8
|
+
f = File.join(File.dirname(__FILE__),'..','data',f+'.txt')
|
9
|
+
tmpip = (f =~ /0\.txt/ ? ip : ip[4,ip.length-1])
|
10
|
+
File.open(f).each do |x|
|
11
|
+
x = x.split(/\s+/,3)
|
12
|
+
return x[2].strip if (format(x[0])..format(x[1])).include?(tmpip)
|
13
|
+
end if File.exist?(f)
|
14
|
+
end
|
15
|
+
|
16
|
+
return "UNKNOW"
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def self.format(ip)
|
21
|
+
ip.to_s.gsub(/\*/,'255').split('.').inject([]) do |s,x|
|
22
|
+
s << [('%03s' % x).gsub(/ /,'0')]
|
23
|
+
end.join('.')
|
24
|
+
end
|
25
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),"..","lib","ipparse.rb")
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestIPParse < Test::Unit::TestCase
|
5
|
+
def test_parse
|
6
|
+
assert_equal IPParse.parse('222.153.3'),false
|
7
|
+
assert_equal IPParse.parse('222.15.153.3'),"江西省云南市"
|
8
|
+
assert_equal IPParse.parse('24.38.192.2'),"美国"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_format
|
12
|
+
assert_equal IPParse.format('12.3.4.23'),'012.003.004.023'
|
13
|
+
assert_equal IPParse.format('12.*.4.23'),'012.255.004.023'
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wosmvp-ipparse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zhang Jinzhu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-16 00:00:00 -08:00
|
13
|
+
default_executable: ipparse
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: IP Parse
|
17
|
+
email: wosmvp@gmail.com
|
18
|
+
executables:
|
19
|
+
- ipparse
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/ipparse.rb
|
24
|
+
- lib/version.rb
|
25
|
+
- bin/ipparse
|
26
|
+
files:
|
27
|
+
- test/test_ipparse.rb
|
28
|
+
- data/203.txt
|
29
|
+
- data/195.txt
|
30
|
+
- data/213.txt
|
31
|
+
- data/81.txt
|
32
|
+
- data/194.txt
|
33
|
+
- data/217.txt
|
34
|
+
- data/80.txt
|
35
|
+
- data/118.txt
|
36
|
+
- data/117.txt
|
37
|
+
- data/212.txt
|
38
|
+
- data/222.txt
|
39
|
+
- data/210.txt
|
40
|
+
- data/116.txt
|
41
|
+
- data/122.txt
|
42
|
+
- data/124.txt
|
43
|
+
- data/119.txt
|
44
|
+
- data/123.txt
|
45
|
+
- data/59.txt
|
46
|
+
- data/60.txt
|
47
|
+
- data/58.txt
|
48
|
+
- data/121.txt
|
49
|
+
- data/193.txt
|
50
|
+
- data/219.txt
|
51
|
+
- data/221.txt
|
52
|
+
- data/192.txt
|
53
|
+
- data/202.txt
|
54
|
+
- data/125.txt
|
55
|
+
- data/211.txt
|
56
|
+
- data/61.txt
|
57
|
+
- data/62.txt
|
58
|
+
- data/218.txt
|
59
|
+
- data/220.txt
|
60
|
+
- lib/ipparse.rb
|
61
|
+
- lib/version.rb
|
62
|
+
- Rakefile
|
63
|
+
- bin/ipparse
|
64
|
+
- Manifest
|
65
|
+
- ipparse.gemspec
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://www.zhangjinzhu.com
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --line-numbers
|
71
|
+
- --inline-source
|
72
|
+
- --title
|
73
|
+
- Ipparse
|
74
|
+
- --main
|
75
|
+
- README
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "1.2"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project: ipparse
|
93
|
+
rubygems_version: 1.2.0
|
94
|
+
signing_key:
|
95
|
+
specification_version: 2
|
96
|
+
summary: IP Parse
|
97
|
+
test_files:
|
98
|
+
- test/test_ipparse.rb
|