macaddr-steakknife 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98d2f145a651cc19d738f1755c5dcb09bb21b834
4
+ data.tar.gz: eb9f51c5a6898fd4af44fc8c7cdf87316c380336
5
+ SHA512:
6
+ metadata.gz: a98a15a9d9c5de171d33fa5a1ab7e186445c3cb59097388695b4e246edff597d49599879fbea4f62565bb117aeb56e6787699f0c37e6a8b3cca22149e0991b2c
7
+ data.tar.gz: 6885cb3fd78ef5708c17b470501433ffc99da71bcf7bc7985898e432d4c7d26110d204653fff886506f023143942266ecdf92bb5fd55f968b3ad8cd4b6c36fe6
checksums.yaml.gz.sig ADDED
Binary file
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ same as ruby's
data/README ADDED
@@ -0,0 +1,59 @@
1
+ NAME
2
+
3
+ macaddr
4
+
5
+ DESCRIPTION
6
+
7
+ cross platform mac address determination for ruby
8
+
9
+ URI
10
+
11
+ http://github.com/steakknife/macaddr
12
+
13
+ (previously)
14
+ http://github.com/ahoward/macaddr
15
+ http://rubyforg.org/projects/codeforpeople
16
+
17
+ INSTALL
18
+
19
+ cd ${TMPDIR-/tmp}
20
+ git clone https://github.com/steakknife/macaddr
21
+ cd macaddr
22
+ gem build *.gemspec
23
+ gem install *.gem
24
+
25
+ Install Gemfile 1.9+
26
+
27
+ gem 'macaddr', git: 'https://github.com/steakknife/macaddr.git'
28
+
29
+ Install Gemfile 1.8+
30
+
31
+ gem 'macaddr', git => 'https://github.com/steakknife/macaddr.git'
32
+
33
+ HISTORY
34
+ Even newer:
35
+ - #ifaddrs - list all Ifaddr's
36
+ - #iface_macs - Hash with all interfaces to mac addresses
37
+ New:
38
+ - Get rid of systemu, only use Ruby's Socket.getifaddrs
39
+ - Actually implement array of all macs as #addrs
40
+ 1.7.x:
41
+ - added a Gemfile for easier testing/dev with Bundler
42
+ - added an example .rvmrc file that will setup for ruby 1.9.3
43
+ - updated systemu gem to ~>2.4.0 to work with ruby 1.9.3
44
+
45
+ 1.1.0:
46
+ - added dependancy on systemu to work around butt-licky windoze io
47
+ capture: http://redmine.ruby-lang.org/issues/show/3215
48
+
49
+ 1.0.0:
50
+ - rdoc added
51
+ - eric hodel kicks ass. to find why, see
52
+ http://drawohara.com/post/44678286/eric-hodel-kicks-ass
53
+
54
+ SYNOPSIS
55
+
56
+ require 'macaddr'
57
+
58
+ Mac.addr #=> first mac addr on your system
59
+ Mac.addrs #=> all mac addrs on your system
@@ -0,0 +1,3 @@
1
+ module MacAddr
2
+ VERSION = "1.8.0".freeze
3
+ end
data/lib/macaddr.rb ADDED
@@ -0,0 +1,141 @@
1
+ autoload :RbConfig, 'rbconfig'
2
+ autoload :Socket, 'socket'
3
+ autoload :Which, 'which'
4
+
5
+ ##
6
+ # Cross platform MAC address determination.
7
+ #
8
+ # To return the first MAC address on the system:
9
+ #
10
+ # Mac.address
11
+ #
12
+ # To return an array of all MAC addresses:
13
+ #
14
+ # Mac.addresses
15
+ module Mac
16
+ extend self
17
+
18
+ # @return [String] First hardware address,
19
+ # in no particular order (varies by system)
20
+ def address
21
+ addresses.first
22
+ end
23
+
24
+ # @return [Array<String>] All hardware address,
25
+ # in no particular order (varies by system)
26
+ def addresses
27
+ iface_macs.values.compact || []
28
+ end
29
+
30
+ alias_method :mac_address, :address
31
+ alias_method :addr, :address
32
+ alias_method :addrs, :addresses
33
+
34
+ # @return [Array<Ifaddr>] Return all interface Ifaddrs
35
+ def ifaddrs
36
+ return [] if !Socket.respond_to?(:getifaddrs) || INTERFACE_PACKET_FAMILY.nil?
37
+ Socket.getifaddrs.select { |iface| iface.addr && iface.addr.pfamily == INTERFACE_PACKET_FAMILY }
38
+ end
39
+
40
+ # @return [Hash<String,[String,nil]>]
41
+ # all interfaces as keys, values are MAC addresses ((if present)
42
+ def iface_macs
43
+ h = iface_macs_raw.map do |k, v|
44
+ v = nil if v.empty? || v !~ EXACT_MAC_REGEX || v =~ EMPTY_MAC
45
+ [k, v]
46
+ end
47
+ Hash[h]
48
+ end
49
+
50
+ INTERFACE_PACKET_FAMILY = [:PF_LINK, :PF_PACKET].map { |c| Socket.const_defined?(c) && Socket.const_get(c) }.first
51
+ EMPTY_MAC = /00(?:[^\h]?00){5}(?:[^\h]?00){2}?/.freeze
52
+ HWADDR_REGEX = /hwaddr=([\h:]+)/.freeze
53
+ 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
+ # EUI48 and EUI64
56
+ LOOSE_MAC_REGEX = /\h\h(?:[^\h]\h\h){5}(?:[^\h]\h\h){2}?/.freeze
57
+ EXACT_MAC_REGEX = /\A#{LOOSE_MAC_REGEX}\z/.freeze
58
+
59
+
60
+ private
61
+
62
+ def iface_macs_raw
63
+ if Socket.const_defined? :PF_LINK
64
+ from_getnameinfo
65
+ elsif Socket.const_defined? :PF_PACKET
66
+ from_inspect_sockaddr
67
+ elsif WINDOWS
68
+ for_windows
69
+ else
70
+ from_ifconfig
71
+ end
72
+ end
73
+
74
+
75
+ def for_windows
76
+ from_ipconfig || from_getmac
77
+ end
78
+
79
+ def clean(arg)
80
+ arg.delete('"')
81
+ end
82
+
83
+ def from_getmac
84
+ return [] unless Which.which 'getmac'
85
+ %x{getmac /fo CSV /nh}
86
+ .split(/\n/)
87
+ .collect { |interface| mac, name = interface.split(/,/); [ clean(name), clean(mac) ] }
88
+ .compact
89
+ end
90
+
91
+ def filter_mac(line)
92
+ line.gsub(/\h\h(?:-\h\h){12}/, "") # delete DHCPv6
93
+ .gsub(/\h{,4}(?::\h{,4}){,31}}/, "") # delete IPv6
94
+ .gsub(/\d{1,3}(?:\.\d{1,3}){3}/, "") # delete IPv4
95
+ .gsub(/00(?:-00){3}(?:-\h\h){4}(?:-\h\h){2}?/, "") # delete Tunnel
96
+ .gsub(/\h{6}(?:-?\h{4}){3}-?\h{12}/, "") # delete GUIDs/UUIDs
97
+ .scan(LOOSE_MAC_REGEX) # mac address(es)
98
+ end
99
+
100
+ def from_ifconfig
101
+ name = nil
102
+ %x{ifconfig}
103
+ .split(/\n/)
104
+ .collect do |line|
105
+ if line =~ /\A([^:\s]+):.*\z/
106
+ name = clean($1)
107
+ nil
108
+ elsif line =~ /(?:ether|HWaddr)\s+/
109
+ mac = filter_mac(line)
110
+ [name, mac.first] if !name.nil? && !mac.empty?
111
+ end
112
+ end
113
+ .compact
114
+ end
115
+
116
+ def from_ipconfig
117
+ name = nil
118
+ %x{ipconfig /all}
119
+ .split(/\n/)
120
+ .collect do |line|
121
+ if line =~ /\A[^:]+\s*adapter\s*([^:]+):\z/
122
+ name = clean($1)
123
+ nil
124
+ else
125
+ mac = filter_mac(line)
126
+ [name, mac] if !name.nil? && !mac.empty?
127
+ end
128
+ end
129
+ .compact
130
+ end
131
+
132
+ def from_getnameinfo
133
+ ifaddrs.map { |iface| mac = iface.addr.getnameinfo[0]; [iface.name, mac] }
134
+ end
135
+
136
+ def from_inspect_sockaddr
137
+ ifaddrs.map { |iface| mac = iface.addr.inspect_sockaddr[HWADDR_REGEX, 1]; [iface.name, mac] }
138
+ end
139
+ end
140
+
141
+ MacAddr = Macaddr = Mac
data/macaddr.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'macaddr/version'
3
+ Gem::Specification::new do |spec|
4
+ spec.name = "macaddr-steakknife"
5
+ spec.version = MacAddr::VERSION
6
+ spec.platform = Gem::Platform::RUBY
7
+ spec.summary = "macaddr"
8
+ spec.description = "Cross-platform mac address determination for ruby"
9
+ spec.license = "Ruby"
10
+
11
+ spec.files =
12
+ ["Gemfile",
13
+ "LICENSE",
14
+ "README",
15
+ "lib/macaddr.rb",
16
+ "lib/macaddr/version.rb",
17
+ "macaddr.gemspec",
18
+ ]
19
+
20
+ spec.require_path = "lib"
21
+
22
+ spec.rubyforge_project = "codeforpeople"
23
+ spec.author = "Ara T. Howard"
24
+ spec.email = "ara.t.howard@gmail.com"
25
+ spec.homepage = "https://github.com/steakknife/macaddr"
26
+ end
27
+ .tap {|gem| pk = File.expand_path(File.join('~/.keys', 'gem-private_key.pem')); gem.signing_key = pk if File.exist? pk; gem.cert_chain = ['gem-public_cert.pem']} # pressed firmly by waxseal
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: macaddr-steakknife
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Ara T. Howard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIFgDCCA2igAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAxiYXJy
14
+ eS5hbGxhcmQxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNjAxMDkxMDE3MTJaFw0xNzAxMDgxMDE3MTJaMEMxFTATBgNVBAMM
16
+ DGJhcnJ5LmFsbGFyZDEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0xJH/kux
18
+ PRBS4y2r4YM+dtEfTOECrEw6JHpQOszJAT8FvJ5cTdPNpUtHGFYUruYRA+qHGM4a
19
+ If/YX7X17W77PvzqFalb1wicroRVDEgbyQWYkLVUL/vKugf7U3YknWhbBxkph23k
20
+ xGG6PO9nMKLk16rPaU6stJJvUjL4Yi7JUSwFWNrgx/t6O/iNzq5kcVR7F+NeCt+W
21
+ sWiXQGm6uZ6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uOYdCSUClmhfFSwiUqj6ncsC
37
+ UqF3y9sr7X7s84Q0JM/rPpkIkRG21jjWhfIBgnH+D5vzlJxdaJpsfuuMx6A1FvxR
38
+ aAQ5nAcQhKJzNZuyAeq9lXv9CZOpjBUQdEiIAjoInIRwoi6fWJEx5dDlYyQ9Kp30
39
+ HZi6DH/HlxTTuPJL6S10KaM/twTVGsNtBvdIBdDksWXkNVQ9no6PSIRS3VNTzG72
40
+ uXxamIDMHelQyBERlaxyDC8pGHWq//wXvg2yG3Z+ZqvpUXaZTiRS7ZQ3zj2yvdqB
41
+ b4WKJs00+KO3etYQG7qD/wH7WEwu3QoLNapYz58Jc0OsDnwBWW0IDPSAFsENoTcY
42
+ 8m+dgfPonsYSqnDDfLuAmtKhLAA=
43
+ -----END CERTIFICATE-----
44
+ date: 2016-02-11 00:00:00.000000000 Z
45
+ dependencies: []
46
+ description: Cross-platform mac address determination for ruby
47
+ email: ara.t.howard@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - Gemfile
53
+ - LICENSE
54
+ - README
55
+ - lib/macaddr.rb
56
+ - lib/macaddr/version.rb
57
+ - macaddr.gemspec
58
+ homepage: https://github.com/steakknife/macaddr
59
+ licenses:
60
+ - Ruby
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project: codeforpeople
78
+ rubygems_version: 2.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: macaddr
82
+ test_files: []
83
+ has_rdoc:
metadata.gz.sig ADDED
Binary file