C # obtain the MAC address and hard disk volume of the device Nic

Source: Internet
Author: User
(1). Description
Obtain the MAC address and hard disk volume of the NIC
(2). Image example

(3). Code
Using system;
Using system. Management;
Namespace netcard
{
/// <Summary>
/// Read the device
/// </Summary>
Public class run
{
Private managementclass MC;

Private managementobjectcollection MOC;

Private managementobject disk;

Public run ()
{
}

/// <Summary>
/// Obtain the MAC address of the device Nic
/// </Summary>
Public
String getnetcardmacaddress ()
{
MC = new managementclass ("win32_networkadapterconfiguration ");
MoC = mc. getinstances ();

String STR = "";
Foreach (managementobject Mo in MoC)
{
If (bool) Mo ["ipenabled"] = true)
STR = Mo ["macaddress"]. tostring ();
}
Return STR;
}

/// <Summary>
/// Obtain the volume ID of the device's hard disk
/// </Summary>
/// <Returns> </returns>
Public
String getdiskvolumeserialnumber ()
{
MC = new managementclass ("win32_networkadapterconfiguration ");
Disk = new managementobject ("win32_logicaldisk.deviceid =" C :"");
Disk. Get ();
Return disk. getpropertyvalue ("volumeserialnumber"). tostring ();
}
}
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.