C 獲取當前主機硬體資訊

2022-03-22 17:42:00 字數 4081 閱讀 8547

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

using system.net;

using system.management; //在專案-》新增引用....裡面引用system.management

using system.runtime.interopservices;

namespace filesplit

static machineinfo instance;

///

/// 獲取當前類物件的乙個例項

///

public static machineinfo i()

///

/// 獲取本地ip位址,多個ip

///

public string getlocalipaddress()

//從**"",獲取本機外網ip位址資訊串

//"\r\n\r\n您的ip是:[218.104.71.178] 來自:安徽省合肥市 聯通

" ///

/// 獲取外網ip位址

///

public string getextenalipaddress()

; string address = "";

string str = getwebstr(address);

try

catch (exception)

return ip;

} ///

/// 獲取**address的返回的文字串資料

///

public string getwebstr(string address)

catch (exception)

return str;

} ///

/// 獲取本機的mac; //在專案-》新增引用....裡面引用system.management

///

public string getlocalmac()

return (mac);

} //只能獲取同網段的遠端主機mac位址. 因為在標準網路協議下,arp包是不能跨網段傳輸的,故想通過arp協議是無法查詢跨網段裝置mac位址的。

[dllimport("iphlpapi.dll")]

private static extern int sendarp(int32 dest, int32 host, ref int64 mac, ref int32 length);

[dllimport("ws2_32.dll")]

private static extern int32 inet_addr(string ip);

///

/// 獲取ip對應的mac位址

///

public string getmacaddress(string ip)

catch (exception err)

", err.message);

} return "獲取mac位址失敗";

} ///

/// 獲取主機板序列號

///

///

public string getbiosserialnumber()

return sbiosserialnumber;

} catch

} ///

/// 獲取cpu序列號

///

///

public string getcpuserialnumber()

return scpuserialnumber;

} catch

} //獲取硬碟序列號

public string getharddiskserialnumber()

return sharddiskserialnumber;

} catch

} //獲取網絡卡位址

public string getnetcardmacaddress()

return netcardmacaddress;

} catch

} ///

/// 獲得cpu編號

///

public string getcpuid()

return cpuid;

} ///

/// 獲取硬碟序列號

///

public string getdiskserialnumber()

return hdid;

/*managementclass mc = new managementclass("win32_physicalmedia");

managementobjectcollection moc = mc.getinstances();

string str = "";

foreach (managementobject mo in moc)

return str;*/

} ///

/// 獲取網絡卡硬體位址

///

public string getmacaddress()

} return mac;

} ///

/// 獲取ip位址

///

public string getipaddress()

} return st;

} ///

/// 作業系統的登入使用者名稱

///

public string getusername()

///

/// 獲取計算機名

///

public string getcomputername()

///

/// 作業系統型別

///

public string getsystemtype()

return st;

} ///

/// 物理記憶體

///

public string getphysicalmemory()

return st;

} ///

/// 顯示卡pnpdeviceid

///

public string getvideopnpid()

return st;

} ///

/// 音效卡pnpdeviceid

///

public string getsoundpnpid()

return st;

} ///

/// cpu版本資訊

///

public string getcpuversion()

return st;

} ///

/// cpu名稱資訊

///

public string getcpuname()

return st;

} ///

/// cpu製造廠商

///

public string getcpumanufacturer()

return st;

} ///

/// 主機板製造廠商

///

public string getboardmanufacturer()

///

/// 主機板編號

///

public string getboardid()

return st;

} ///

/// 主機板型號

///

c 獲取硬體資訊

using system using system.runtime.interopservices using system.management namespace hardware 取cpu編號 public string getcpuid return strcpuid catch end m...

c 獲取硬體資訊

using system using system.runtime.interopservices using system.management namespace hardware 取cpu編號 public string getcpuid return strcpuid catch end m...

C 獲取硬體資訊

using system using system.net using system.runtime.interopservices using system.management 需要在解決方案中引用system.management.dll檔案 獲取機器名 public string getho...