pingfacts 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e292ddadb1df2eacdb19ad584f375451a97cb5ad215198c91002c28a1e131c48
4
- data.tar.gz: 1e42044bfa77c46f96c55e3b3e45f6b88a6baa39167e1be9fb2f5d58e1f6f41b
3
+ metadata.gz: 5880c3130b81fd512994a5c36a3ad567b1fd5919e55287df1f9e02b2fe859b6f
4
+ data.tar.gz: ca8f8df30be102cd62e96d817cc55f0748d1cd79d8957abb3203c62bbe3688d5
5
5
  SHA512:
6
- metadata.gz: a4655c52d704d5a19a9daf70ea8a240a638b11c2eea54d71aaf396741ff664b41e7002edee0cfb0c9d23e9f581a5e4b5248a2ad88ba54a345a8c692db5af8f99
7
- data.tar.gz: 80ddf560aaa5887b2bc0983a02bfdc6fb03f87a587b015f322b334700c3d3f0af048c23d29f9e88e22a348e976f8cfe53b9e1301aed60c46e25ab22288fb0b50
6
+ metadata.gz: '05008e388edfca4ef1c4307819631951d947bb06fbc8b19e82f2f10c27e06bc5208c65e9476a54ebbfe1fd426c520742a0dc5a37bdac19f4eff5b6a5f7accc80'
7
+ data.tar.gz: 50c9e2a913413ef74c4d47f8112d0bc134d821fc8b202bba921523b4eb3c741dfdcf042642705239acae3653dfd1e52e37b9d8af3c24cdd13f2eb1f7c5196cb7
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pingfacts (0.1.0)
4
+ pingfacts (0.1.2)
5
+ net-ping (~> 2.0)
6
+ pry (~> 0.13)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
@@ -1,4 +1,6 @@
1
1
  require "pingfacts/version"
2
+ require "open-uri"
3
+ require "etc"
2
4
  require "ipaddr"
3
5
  require "resolv"
4
6
  require "net/ping"
@@ -7,20 +9,137 @@ module Pingfacts
7
9
  class Error < StandardError; end
8
10
 
9
11
  class PingerResult
12
+ @@strictmode = false
13
+ begin
14
+ @@configs = "#{Etc.getpwuid.dir}/.pingfacts"
15
+ rescue NoMethodError
16
+ @@configs = "#{File.expand_path('~')}/.pingfacts"
17
+ end
18
+ @@vendors = nil
19
+
10
20
  attr_accessor :ip, :dnsname, :mac
11
- end
12
21
 
13
- def self.scan(network, method=Net::Ping::External)
14
- ip_range = IPAddr.new(network).to_range
22
+ def self.strictmode
23
+ @@strictmode
24
+ end
25
+
26
+ def self.strictmode=(new_value)
27
+ @@strictmode = new_value
28
+ end
29
+
30
+ def self.configs
31
+ @@configs
32
+ end
15
33
 
34
+ def self.configs=(new_value)
35
+ @@configs = new_value
36
+ end
37
+
38
+ def path_vendorlist
39
+ "#{@@configs}/vendorlist"
40
+ end
41
+
42
+ def prepare_configs
43
+ begin
44
+ Dir.mkdir(@@configs)
45
+ rescue Errno::EEXIST
46
+ end
47
+
48
+ vendor_content = nil
49
+
50
+ unless File.exist? path_vendorlist
51
+ vendor_content = URI.open("http://standards-oui.ieee.org/oui/oui.txt").read
52
+ open(path_vendorlist, "w") do |file|
53
+ file << vendor_content
54
+ end
55
+ else
56
+ if @@vendors.nil?
57
+ open(path_vendorlist, "r") do |file|
58
+ vendor_content = file.read
59
+ end
60
+ end
61
+ end
62
+
63
+ if @@vendors.nil? and (not vendor_content.nil?)
64
+ @@vendors = {}
65
+ vendor_content.lines.each do |line|
66
+ if (/\(base\s+16\)/i).match(line)
67
+ result = (/^([0-9A-F]+)\s+\(base\s+16\)\s+(.+)$/i).match(line)
68
+ unless result.nil?
69
+ @@vendors[result[1]] = result[2]
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def eql?(other)
77
+ if @@strictmode
78
+ return (self.ip == other.ip and self.mac == other.mac and self.dnsname == other.dnsname)
79
+ end
80
+ result = false
81
+ if self.mac != nil and other.mac != nil
82
+ if self.mac == other.mac
83
+ result = true
84
+ end
85
+ end
86
+ if self.dnsname != nil and other.dnsname != nil
87
+ if self.dnsname == other.dnsname
88
+ return true
89
+ end
90
+ end
91
+ if self.ip != nil and other.ip != nil
92
+ if self.ip == other.ip
93
+ result = true
94
+ end
95
+ end
96
+
97
+ return result
98
+ end
99
+
100
+ def vendor
101
+ if self.mac.nil?
102
+ return nil
103
+ end
104
+ self.prepare_configs
105
+ teststring = self.mac.upcase.gsub /[^0-9A-F]*/i, ""
106
+ result = @@vendors[teststring[0,6]]
107
+ if result.nil?
108
+ return nil
109
+ end
110
+ return result.strip
111
+ end
112
+ end
113
+
114
+ def self.scan(network_args, method=Net::Ping::External)
115
+ network_list = []
16
116
  pingers = []
17
117
  onlines = []
18
118
 
19
- ip_range.each do |ip|
20
- pingers << Thread.new do
21
- pinger = Net::Ping::External.new(ip.to_s)
22
- if pinger.ping?
23
- onlines << ip.to_s
119
+ if network_args.class == Array
120
+ network_list += network_args
121
+ else
122
+ network_list << network_args
123
+ end
124
+
125
+ network_list.each do |network|
126
+ begin
127
+ ip_range = IPAddr.new(network).to_range
128
+
129
+ ip_range.each do |ip|
130
+ pingers << Thread.new do
131
+ pinger = Net::Ping::External.new(ip.to_s)
132
+ if pinger.ping?
133
+ onlines << ip.to_s
134
+ end
135
+ end
136
+ end
137
+ rescue IPAddr::InvalidAddressError
138
+ pingers << Thread.new do
139
+ pinger = Net::Ping::External.new(network)
140
+ if pinger.ping?
141
+ onlines << network
142
+ end
24
143
  end
25
144
  end
26
145
  end
@@ -38,6 +157,7 @@ module Pingfacts
38
157
  end
39
158
  end
40
159
  rescue
160
+ nil
41
161
  end
42
162
 
43
163
  result = []
@@ -50,7 +170,11 @@ module Pingfacts
50
170
  end
51
171
  begin
52
172
  ipresult.dnsname = Resolv.getname(ip)
173
+ rescue Resolv::ResolvError
174
+ ipresult.ip = Resolv.getaddress(ip)
175
+ ipresult.dnsname = ip
53
176
  rescue
177
+ nil
54
178
  end
55
179
 
56
180
  result << ipresult
@@ -1,3 +1,3 @@
1
1
  module Pingfacts
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingfacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian E.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-08 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ping
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.1.3
86
+ rubygems_version: 3.1.4
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: Another Ping-Tool with additional Mac-Address information and DNS-Resolv-Name