How to Validate the Mac ID'
How to Validate the MacId's While installing the Software.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Apr 1, 2012, 11:37 PM EDT
If you have the MAC address and want to validate then
bool isValid = Regex.IsMatch(sMacAdd, "/^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$");
There are few ways to get the MAC address of the clients, then
http://www.dotnetboss.com/2010/04/27/how-to-get-mac-address-using-c/
siri28 reputationPosted Apr 2, 2012, 12:19 AM EDT
siri28 reputationPosted Apr 17, 2012, 10:34 PM EDT
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}
MACAddress = MACAddress.Replace(":", "");
return MACAddress;
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = GetMACAddress();
string MyMacID = "00E04C36008K";
string MACAddress = GetMACAddress();
if (string.Equals(MyMacID, MACAddress) == true)
{
MessageBox.Show("Valid");
}
else
{
MessageBox.Show("Invalid");
}
}
Code is working
Kunal VaishyaRank #990 · 2K reputationPosted Apr 18, 2012, 12:27 AM EDT
private string GetMACAddress() { try { //Using System.Management ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); string MACAddress = string.Empty; foreach (ManagementObject mo in moc) { if ((MACAddress.Equals(string.Empty))) { if (Convert.ToBoolean(mo("IPEnabled"))) MACAddress = mo("MacAddress").ToString(); mo.Dispose(); } MACAddress = MACAddress.Replace(":", "-"); } return MACAddress; } catch (Exception ex) { } }