net-ip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/net/ip/route.rb +74 -16
- data/lib/net/ip/version.rb +1 -1
- data/net-ip.gemspec +1 -0
- metadata +20 -4
data/lib/net/ip/route.rb
CHANGED
@@ -1,28 +1,86 @@
|
|
1
1
|
module Net
|
2
2
|
module IP
|
3
3
|
class Route
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
attr_accessor :type, :prefix, :dev, :scope, :metric,
|
5
|
+
:proto, :src, :via, :weight, :table, :error
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
str = ""
|
9
|
+
str << type << " " if type != "unicast"
|
10
|
+
str << prefix << " "
|
11
|
+
|
12
|
+
str << "via #{via} " if via
|
13
|
+
|
14
|
+
str << "dev #{dev} " if dev
|
15
|
+
|
16
|
+
str << " table #{table} " if table
|
17
|
+
str << " proto #{proto} " if proto
|
18
|
+
str << " scope #{scope} " if scope
|
19
|
+
|
20
|
+
str << " src #{src} " if src
|
21
|
+
str << " metric #{metric} " if metric
|
22
|
+
|
23
|
+
str << " error #{error}" if error
|
24
|
+
|
25
|
+
str
|
19
26
|
end
|
20
27
|
|
21
28
|
def self.all
|
22
|
-
`ip route
|
29
|
+
parse(`ip route show table 0`)
|
23
30
|
end
|
24
31
|
|
25
32
|
private
|
33
|
+
|
34
|
+
def self.parse_line(line)
|
35
|
+
route = new
|
36
|
+
|
37
|
+
if line =~ /^(unicast|unreachable|blackhole|prohibit|local|broadcast|throw|nat|via|anycast|multicast)\s+/
|
38
|
+
route.type = $1
|
39
|
+
line = line[$1.length..-1]
|
40
|
+
else
|
41
|
+
route.type = "unicast"
|
42
|
+
end
|
43
|
+
|
44
|
+
route.prefix = line.split.first
|
45
|
+
route.dev = $1 if line =~ /\s+dev\s+([^\s]+)/
|
46
|
+
route.scope = $1 if line =~ /\s+scope\s+([^\s]+)/
|
47
|
+
route.metric = $1 if line =~ /\s+metric\s+([^\s]+)/
|
48
|
+
route.proto = $1 if line =~ /\s+proto\s+([^\s]+)/
|
49
|
+
route.src = $1 if line =~ /\s+src\s+([^\s]+)/
|
50
|
+
route.via = $1 if line =~ /\s+via\s+([^\s]+)/
|
51
|
+
route.weight = $1 if line =~ /\s+weight\s+([^\s]+)/
|
52
|
+
route.table = $1 if line =~ /\s+table\s+([^\s]+)/
|
53
|
+
route.error = $1 if line =~ /\s+error\s+([^\s]+)/
|
54
|
+
|
55
|
+
route
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.parse_data(data, &block)
|
59
|
+
in_default = false
|
60
|
+
data.each_line do |line|
|
61
|
+
if in_default == true
|
62
|
+
if line.start_with? "\t"
|
63
|
+
yield(parse_line(line.strip.gsub("nexthop", "default")))
|
64
|
+
else
|
65
|
+
in_default = false
|
66
|
+
end
|
67
|
+
elsif line.strip == "default"
|
68
|
+
in_default = true
|
69
|
+
end
|
70
|
+
|
71
|
+
unless in_default
|
72
|
+
yield(parse_line(line.strip))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.parse(data)
|
78
|
+
list = []
|
79
|
+
parse_data(data) do |route|
|
80
|
+
list << route
|
81
|
+
end
|
82
|
+
list
|
83
|
+
end
|
26
84
|
end
|
27
85
|
end
|
28
86
|
end
|
data/lib/net/ip/version.rb
CHANGED
data/net-ip.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description:
|
47
63
|
email:
|
48
64
|
- jbussdieker@gmail.com
|
@@ -74,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
90
|
version: '0'
|
75
91
|
segments:
|
76
92
|
- 0
|
77
|
-
hash:
|
93
|
+
hash: 898382037184904844
|
78
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
95
|
none: false
|
80
96
|
requirements:
|
@@ -83,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
99
|
version: '0'
|
84
100
|
segments:
|
85
101
|
- 0
|
86
|
-
hash:
|
102
|
+
hash: 898382037184904844
|
87
103
|
requirements: []
|
88
104
|
rubyforge_project:
|
89
105
|
rubygems_version: 1.8.25
|