[英]c# How to get info about a computer using IP address
我想獲取有關使用IPv4地址的計算機的信息。 目前,我只能獲取名稱和IPv4。 但是我想要:IPv4,IPv6,MAC,名稱,有關OS的信息等。我該怎么做? 如果這是重復的,也表示抱歉。
編輯:這是我用來獲取信息的代碼(我不得不翻譯它)
public static string[] PingPC(string address, string data)
{
string[] info = new string[5];
try
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 100;
PingReply reply = pingSender.Send(address, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
info[0] = reply.Address.ToString();
IPHostEntry hostentry = Dns.GetHostEntry(info[0]);
info[1] = hostentry.HostName;
info[2] = reply.Buffer.Length.ToString();
info[3] = reply.Options.Ttl.ToString();
info[4] = reply.RoundtripTime.ToString();
return info;
}
}
catch (Exception e)
{
throw new CantPingException();
}
return info;
}
您可以使用WMI
,從中可以訪問有關PC的各種信息。 這些信息包括CPU序列號,內部版本號,系統序列號等。您只需找到正確的對象並編寫正確的查詢即可。 由於本主題的上下文很大,因此我僅提供一個示例,可以幫助您了解使用WMI的一些想法,並且應該在MSDN文檔中查找所需的內容。
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
var processorId = mo.Properties["processorID"].Value.ToString();
break;
}
請參考此鏈接以獲取更多信息。
根據MSDN,以下類為您提供了有關這些的信息:
[Dynamic, Provider("CIMWin32"), UUID("{8502C4C0-5FBB-11D2-AAC1-006008C78BC7}"), AMENDMENT]
class Win32_NetworkAdapter : CIM_NetworkAdapter
{
string AdapterType;
uint16 AdapterTypeID;
boolean AutoSense;
uint16 Availability;
string Caption;
uint32 ConfigManagerErrorCode;
boolean ConfigManagerUserConfig;
string CreationClassName;
string Description;
string DeviceID;
boolean ErrorCleared;
string ErrorDescription;
string GUID;
uint32 Index;
datetime InstallDate;
boolean Installed;
uint32 InterfaceIndex;
uint32 LastErrorCode;
string MACAddress;
string Manufacturer;
uint32 MaxNumberControlled;
uint64 MaxSpeed;
string Name;
string NetConnectionID;
uint16 NetConnectionStatus;
boolean NetEnabled;
string NetworkAddresses[];
string PermanentAddress;
boolean PhysicalAdapter;
string PNPDeviceID;
uint16 PowerManagementCapabilities[];
boolean PowerManagementSupported;
string ProductName;
string ServiceName;
uint64 Speed;
string Status;
uint16 StatusInfo;
string SystemCreationClassName;
string SystemName;
datetime TimeOfLastReset;
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.