Skip to content

Commit ea9fcc1

Browse files
committed
Fixed Node ID for generated UUID v1 to check for valid MAC address.
1 parent 6fb68a2 commit ea9fcc1

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [v2.3.1] - 2025-07-01
12+
[v2.3.1](https://github.com/TensionDev/UUIDUtil/releases/tag/v2.3.1)
13+
14+
### Fixed
15+
- Fixed Node ID for generated UUID v1 to check for valid MAC address.
16+
17+
1118
## [v2.3.0] - 2025-03-30
1219
[v2.3.0](https://github.com/TensionDev/UUIDUtil/releases/tag/v2.3.0)
1320

UUIDUtil/UUIDUtil.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1212
<PackageId>TensionDev.UUID</PackageId>
13-
<Version>2.3.0</Version>
13+
<Version>2.3.1</Version>
1414
<Authors>TensionDev amsga</Authors>
1515
<Company>TensionDev</Company>
1616
<Product>TensionDev.UUID</Product>

UUIDUtil/UUIDv1.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// limitations under the License.
1616

1717
using System;
18+
using System.Linq;
1819

1920
namespace TensionDev.UUID
2021
{
@@ -127,14 +128,20 @@ public static Byte[] GetNodeID()
127128
{
128129
if (System.Net.NetworkInformation.PhysicalAddress.None.Equals(s_physicalAddress))
129130
{
130-
System.Net.NetworkInformation.NetworkInterface[] networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
131-
if (networkInterfaces.Length > 0)
131+
var networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
132+
foreach (var networkInterface in networkInterfaces)
132133
{
133-
s_physicalAddress = networkInterfaces[0].GetPhysicalAddress();
134+
var address = networkInterface.GetPhysicalAddress();
135+
if (!address.Equals(System.Net.NetworkInformation.PhysicalAddress.None))
136+
{
137+
s_physicalAddress = address;
138+
break;
139+
}
134140
}
135-
else
141+
if (s_physicalAddress.Equals(System.Net.NetworkInformation.PhysicalAddress.None))
136142
{
137-
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
143+
// Fallback to random
144+
using (var cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
138145
{
139146
Byte[] fakeNode = new Byte[6];
140147
cryptoServiceProvider.GetBytes(fakeNode);

0 commit comments

Comments
 (0)