mac_man 0.1.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
+ SHA256:
3
+ metadata.gz: 3a8790951bcf3fb9153ced86590979b8bf7c4f17a558511a4f4f363d274ab52f
4
+ data.tar.gz: cc955f42f5b29e2b971976f7b6ac192626b6e3635c4488f72f2cc8594674536b
5
+ SHA512:
6
+ metadata.gz: f1c311f3fd4fe510fab198cc335381232a1832f6729da7f2cf1c6dd90bfb5b4992ab9376a1b355d40ed7979b2046f3be00929b092ec1ddcac09d911cf77288fd
7
+ data.tar.gz: 74ce41ae1e531e7dd2a09bdc6c78cbb93bcdd01d5b6c5b90810eb5fd09f63ad873684a80a9e3fda88f5f4e9ab4654cb0fbbc6f8d5660555cc3f70047c67234ac
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # MacMac
2
+
3
+ You want to generate Your own Mac Addresses or manipulate exiting addresses? Mac Man has you covered.
4
+
5
+ ## Create Random addresses
6
+
7
+ Completely randomized address. Mac Man ensures that the broadcast flag is not set and the locally administered flag is set.
8
+
9
+ ```ruby
10
+ random_address = MacMan::Address.new
11
+ ```
12
+
13
+ ## Create Random address with prefix
14
+
15
+ Create Address where the NIC part is randomized but the prefix is fix.
16
+
17
+ ```ruby
18
+ random_address = MacMan::Address.new(oui: 0xAB_CD_EF)
19
+ ```
20
+
21
+
22
+
23
+
24
+
25
+
@@ -0,0 +1,66 @@
1
+ module MacMan
2
+ BROADCAST_BITMASK = 0x01_00_00_00_00_00
3
+ LOCAL_ADMINISTERED_BITMASK = 0x02_00_00_00_00_00
4
+
5
+ class Address
6
+
7
+ attr_accessor :address
8
+
9
+ # MAC Address for manipulation
10
+ #
11
+ # @param address [String] A MAC address for manipulation
12
+ # @param oui [Sring] The Organizationally Uniqe Identifier of the Address. The second half is randomized.
13
+ def initialize(**args)
14
+ if args[:address]
15
+ @address = args[:address]
16
+ elsif args[:oui]
17
+ @address = (args[:oui] << 24 ) + rand(0..0xFFFFFF)
18
+ else
19
+ @address = rand(0..0xFF_FF_FF_FF_FF_FF)
20
+ self.unset_broadcast_bit
21
+ self.set_locally_administered_bit
22
+ end
23
+ end
24
+
25
+ # Human readable Text representation of the address
26
+ #
27
+ # @param delimiter [String] Set the delimiter used to separate the address. Default: ':'(colon)
28
+ def to_hex(delimiter: ':')
29
+ @address.to_s(16).chars.each_slice(2).map(&:join).join(delimiter)
30
+ end
31
+
32
+ # Checks if the address is locally administered
33
+ #
34
+ # @see: https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit)
35
+ def locally_administered?
36
+ (@address & LOCAL_ADMINISTERED_BITMASK) > 0
37
+ end
38
+
39
+ # Checks if the address has the broadcast flag set
40
+ #
41
+ # @see https://en.wikipedia.org/wiki/MAC_address#Unicast_vs._multicast_(I/G_bit)
42
+ def broadcast_address?
43
+ (@address & BROADCAST_BITMASK) > 0
44
+ end
45
+
46
+ # Enables the locally administered flag
47
+ #
48
+ # @see: https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit)
49
+ def set_locally_administered_bit
50
+ @address |= LOCAL_ADMINISTERED_BITMASK
51
+ end
52
+
53
+ # Disables the Broadcast flag
54
+ #
55
+ # @see https://en.wikipedia.org/wiki/MAC_address#Unicast_vs._multicast_(I/G_bit)
56
+ #
57
+ def unset_broadcast_bit
58
+ @address ^= BROADCAST_BITMASK
59
+ end
60
+
61
+ def to_s
62
+ to_hex
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module MacMan
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mac_man
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Moritz Kraus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Generate and manipulate mac addresses
14
+ email: moritz.kraus@makandra.de
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/mac_man/address.rb
21
+ - lib/mac_man/version.rb
22
+ homepage: https://makandra.com
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ rubygems_mfa_required: 'true'
27
+ source_code_uri: https://github.com/moritz-makandra/mac_man
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.3.7
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Manipulate MAC addresses
47
+ test_files: []