Comments (10)
If you just want to use the physical ethernet adapters, you could do something like:
public class CustomMacAddressDeviceIdComponent : IDeviceIdComponent
{
public string GetValue()
{
var values = NetworkInterface.GetAllNetworkInterfaces()
.Where(x => x.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
.Select(x => x.GetPhysicalAddress().ToString())
.ToList();
values.Sort();
return values.Count > 0
? string.Join(",", values.ToArray())
: null;
}
}
and then use it as so:
var deviceId = new DeviceIdBuilder()
.AddUserName()
.AddMachineName()
.AddComponent("MacAddress", new CustomMacAddressDeviceIdComponent())
.ToString();
You can to adjust the NetworkInterfaceType filtering to match the exact types you want to use.
from deviceid.
Thank you, I will try it for a day or two and report back. Really appreciate your quick response.
from deviceid.
I think this should fix my issue. I will update later on.
NetworkInterface
.GetAllNetworkInterfaces()
.Where(nic => nic.OperationalStatus == OperationalStatus.Up
&& nic.NetworkInterfaceType != NetworkInterfaceType.Loopback
&& nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
.Select(nic => nic.GetPhysicalAddress().ToString())
.ToList()
from deviceid.
In an ideal situation, it shouldn't be changing. It's not meant to change. But without knowing what's actually going on with your device, it's hard to say what's happening.
I will note that the out-of-the-box AddMacAddress implementation isn't ideal - it aggregates the physical addresses of all network interface types attached to the system, and some of these may change over time. I'd like to improve this, but doing so would break backwards compatibility for a lot of apps.
You can look at the code here, and perhaps make a custom component that filters NetworkInterfaceType to only types that you care about.
from deviceid.
Thank you for the quick response.
So, I have a laptop. I didn't change the "ISP" & "IP" during those 24 hours. I was using wireless and stayed on wireless during that time. I have a console app (POC) which uses your package to generate unique Id every 15 minutes and logs that Id in the database. So, it changed for 3 rows (1 hours 30 min) and then reverted back to original ID.
So it generated initially "xyz" ID then for 3 rows (for just 1 hour 30 min in total 24 hours) it generated "abc" but after that it reverted to "xyz" again.
Can we just take the physical NIC ethernet's MAC as seed, cuz it should stay same all the time, no? If we can implement it, how can I go about it.
from deviceid.
Just to add to my previous comment. My purpose is to find a unique hardware identifier actually so every time a system is connected to my DB or service, I can verify it based on a device Id that it is authorized for access.
from deviceid.
@MatthewKing I ran my windows service for ~36 hours straight and it generated 2 unique ids during these hours using the code that you gave me. I am so confused as to what is happening, if you could help me in this that would be great.
from deviceid.
Defintiely worth trying the updated code you've suggested. I hope it works for you.
Beyond that, it's entirely dependent on what's getting returned by NetworkInterface.GetAllNetworkInterfaces()
which is part of the .NET base class library. Without seeing exactly what's going on with your environment, I don't know enough about it to say why it's changing what it returns.
Alternatively, you could try using different hardware components to generate your device ID instead?
from deviceid.
I have tweaked the logic a bit for our case, so for uniqueness now I save the MAC as comma separated directly and if any of the mac exists that means the computer is same during a verification call.
I think we can add a way of just getting the direct MACs instead of encoding them, if there is I would like to know.
from deviceid.
Hi, an update. As I told you that now I am saving MAC address in a comma separated to see what is going on.
I can see that randomly within 36 hour time frame a new MAC is registered along with previous ones.
So, previously I have 2 MACs getting registered "xyz, abc," now after few hours it adds new one "xyz, abc, zxc". This is the reason why the deviceId changes within 36 hour period as the seed changes.
Why seed/mac list changes ?
This is because I turn on my "Bluetooth" for a few hours for meetings. During this time, it adds a new "MAC" (why it's filtered with Ethernet though? I am confused). If I turn off my Bluetooth, it will then return back to same 2 MAC, hence generating same unique id.
I hope this helps you as well in improving this library, thank you
from deviceid.
Related Issues (20)
- How to get deviceId from Client ? HOT 1
- Not Generating DeviceId on CentOs 7
- Could not load file or assembly 'System.Management HOT 1
- [Question] DeviceId 6.3 nuget release dates? HOT 3
- JsonException when generating Id on Alpine Linux HOT 1
- DeviceId doesn't work in docker for Windows containers. HOT 2
- IOS/Android HOT 1
- Device ID on docker container HOT 4
- Validate the DeviceId is semantically correct HOT 1
- DeviceIdBuilder AddSystemDriveSerialNumber() - System.Management.ManagementException: Invalid class HOT 2
- Docker0 bridge interface is including to macaddress
- AddCpuInfo always return new id
- Downgrade the System.Management dependency to version 6 for .net standard 2.0
- MacAddress changes HOT 1
- NET8.0 DeviceId.Windows.Mmi not working HOT 3
- Using package DeviceId.Wmi - MotherboardSerialNumber gives WPF scroll issues HOT 2
- Needed Signed Version of DeviceID Assemblies HOT 1
- AddWindowsDeviceId() and AddWindowsProductId() in 32 bit processes HOT 1
- AddUserName() on Windows: Optionally normalize case HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deviceid.