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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal VaishyaPosted Apr 18, 2012, 4:27 AM
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) {
} }
siriPosted Apr 18, 2012, 2:34 AM
{
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
siriPosted Apr 2, 2012, 4:19 AM
SenthilkumarPosted Apr 2, 2012, 3:37 AM
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/