我想获取有关使用IPv4地址的计算机的信息。目前,我只能获取名称和IPv4。但是我想要: IPv4, IPv6, 苹果电脑, 名称, 有关操作系统的信息, 等等。我该怎么做?如果这是重复的,也表示抱歉。
编辑:这是我用来获取信息的代码(我必须对其进行翻译)
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;
}
答案 0 :(得分:0)
您可以利用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;
}
有关更多信息,请参阅此link。
根据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;
};