[英]c# How to get info about a computer using IP address
I want to get information about a computer using an IPv4 address. 我想获取有关使用IPv4地址的计算机的信息。 Currently, I can only get the name and IPv4.
目前,我只能获取名称和IPv4。 But I want: IPv4, IPv6, MAC, Name, info about OS, etc. How can I do this?
但是我想要:IPv4,IPv6,MAC,名称,有关OS的信息等。我该怎么做? Also sorry if this is a duplicate.
如果这是重复的,也表示抱歉。
Edit: Here is the code I use to get info(I had to translate it) 编辑:这是我用来获取信息的代码(我不得不翻译它)
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;
}
You can make use of WMI
from which you can gain access to a wide range of information regarding a PC. 您可以使用
WMI
,从中可以访问有关PC的各种信息。 Such information include CPU Serial Number, Build Number, System Serial Number, etc. You just have to find the right object and write the right query. 这些信息包括CPU序列号,内部版本号,系统序列号等。您只需找到正确的对象并编写正确的查询即可。 Since the context of this topic is very large, I will only provide an example which can help you get some idea over using WMI, and you should look up what you need in MSDN documentation.
由于本主题的上下文很大,因此我仅提供一个示例,可以帮助您了解使用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;
}
Please refer to this link for more information. 请参考此链接以获取更多信息。
In accordance with MSDN, the following class gives you information about these: 根据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.