macaddr-steakknife 1.8.3 → 1.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/macaddr/version.rb +1 -1
- data/lib/macaddr.rb +19 -11
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 890f0a3e388843c737f822965f48050fa402616e
|
4
|
+
data.tar.gz: 7c09951010eb863022305b80c45a063e0509137d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c32818ecac8fae55ac908bcf37a7d22d96a5c7e16780e045e0d43a815359c48b4005ebf0af96eac9c96f360a1a315f7717a77d6f6e1b36afef26b30e86c2f31
|
7
|
+
data.tar.gz: 7fb572c02cdb14106ea210db640e6bfca0a7a31197bebb0aadcc6dae901fbc1f3695ce29c2a11ac8c802f8651f66fef0d1f2562477cc9661b25494235ad051f9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/macaddr/version.rb
CHANGED
data/lib/macaddr.rb
CHANGED
@@ -33,44 +33,52 @@ module Mac
|
|
33
33
|
|
34
34
|
# @return [Array<Ifaddr>] Return all interface Ifaddrs
|
35
35
|
def ifaddrs
|
36
|
-
return [] if !Socket.respond_to?(:getifaddrs) ||
|
37
|
-
Socket.getifaddrs.select { |iface| iface.addr && iface.addr.pfamily ==
|
36
|
+
return [] if !Socket.respond_to?(:getifaddrs) || iface_packet_family.nil?
|
37
|
+
Socket.getifaddrs.select { |iface| iface.addr && iface.addr.pfamily == iface_packet_family }
|
38
38
|
end
|
39
39
|
|
40
40
|
# @return [Hash<String,[String,nil]>]
|
41
41
|
# all interfaces as keys, values are MAC addresses ((if present)
|
42
42
|
def iface_macs
|
43
43
|
h = iface_macs_raw.map do |k, v|
|
44
|
-
v = nil
|
44
|
+
v = nil unless valid_mac? v
|
45
45
|
[k, v]
|
46
46
|
end
|
47
47
|
Hash[h]
|
48
48
|
end
|
49
49
|
|
50
|
-
INTERFACE_PACKET_FAMILY = [:PF_LINK, :PF_PACKET].map { |c| Socket.const_defined?(c) && Socket.const_get(c) }.first
|
51
50
|
EMPTY_MAC = /00(?:[^\h]?00){5}(?:[^\h]?00){2}?/.freeze
|
52
51
|
HWADDR_REGEX = /hwaddr=([\h:]+)/.freeze
|
53
52
|
WINDOWS_REGEX = /win(32|dows|ce)|(ms|cyg|bcc)win|mingw32|djgpp/i.freeze
|
54
|
-
WINDOWS = RbConfig::CONFIG["host_os"] =~ WINDOWS_REGEX || RUBY_PLATFORM =~ WINDOWS_REGEX || ENV['OS'] == 'Windows_NT'
|
55
53
|
# EUI48 and EUI64
|
56
54
|
LOOSE_MAC_REGEX = /\h\h(?:[^\h]\h\h){5}(?:[^\h]\h\h){2}?/.freeze
|
57
55
|
EXACT_MAC_REGEX = /\A#{LOOSE_MAC_REGEX}\z/.freeze
|
58
56
|
|
59
|
-
|
60
57
|
private
|
61
58
|
|
59
|
+
def valid_mac?(s)
|
60
|
+
!s.nil? && !s.empty? && s =~ EXACT_MAC_REGEX && s != EMPTY_MAC
|
61
|
+
end
|
62
|
+
|
63
|
+
def windows?
|
64
|
+
@windows ||= RbConfig::CONFIG["host_os"] =~ WINDOWS_REGEX || RUBY_PLATFORM =~ WINDOWS_REGEX || ENV['OS'] == 'Windows_NT'
|
65
|
+
end
|
66
|
+
|
67
|
+
def iface_packet_family
|
68
|
+
@iface_packet_family ||= (Socket::PF_LINK if defined? Socket::PF_LINK) || (Socket::PF_PACKET if defined? Socket::PF_PACKET)
|
69
|
+
end
|
70
|
+
|
62
71
|
def iface_macs_raw
|
63
|
-
if
|
72
|
+
if defined? Socket::PF_LINK
|
64
73
|
from_getnameinfo
|
65
|
-
elsif
|
74
|
+
elsif defined? Socket::PF_PACKET
|
66
75
|
from_inspect_sockaddr
|
67
|
-
elsif
|
76
|
+
elsif windows?
|
68
77
|
for_windows
|
69
78
|
else
|
70
79
|
from_ifconfig
|
71
80
|
end
|
72
81
|
end
|
73
|
-
|
74
82
|
|
75
83
|
def for_windows
|
76
84
|
from_ipconfig || from_getmac
|
@@ -140,6 +148,6 @@ module Mac
|
|
140
148
|
def from_inspect_sockaddr
|
141
149
|
ifaddrs.map { |iface| mac = iface.addr.inspect_sockaddr[HWADDR_REGEX, 1]; [iface.name, mac] }
|
142
150
|
end
|
143
|
-
end
|
151
|
+
end # Mac
|
144
152
|
|
145
153
|
MacAddr = Macaddr = Mac
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|