Had a gentleman answer 90% of my original question, which is to say I now have the ability to poll a device that I am running the below script on. The end goal is to obtain IP type: Static or DHCP on all desktop/servers on a network I support. I have the list of servers that I will input in a batch file, just looking for the code to actually poll the other devices on the network from one location.
Output to be viewed:
Device name: IP Address: MAC Address: Type: Marvell Yukon 88E8001/8003/8010 PCI Gigabit Ethernet Controller NULL 00:00:F3:44:C6:00 DHCP Generic Marvell Yukon 88E8056 based Ethernet Controller 192.168.1.102 00:00:F3:44:D0:00 DHCP
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
txtLaunch.Text = ("Name\tIP Address\tMAC Address\tType" +"\r\n");
foreach (ManagementObject objMO in objMOC)
{
StringBuilder builder = new StringBuilder();
object o = objMO.GetPr开发者_高级运维opertyValue("IPAddress");
object m = objMO.GetPropertyValue("MACAddress");
if (o != null || m != null)
{
builder.Append(objMO["Description"].ToString());
builder.Append("\t");
if (o != null)
builder.Append(((string[])(objMO["IPAddress"]))[0].ToString());
else
builder.Append("NULL");
builder.Append("\t");
builder.Append(m.ToString());
builder.Append("\t");
builder.Append(Convert.ToBoolean(objMO["DHCPEnabled"]) ? "DHCP" : "Static");
builder.Append("\r\n");
}
txtLaunch.Text = txtLaunch.Text + (builder.ToString());
I'm open to recommendations here.
You just need to instantiate your management class on the remote machine.
This link: Remote WMI will give you the code you need. Just loop through with each machine and get the info you need.
You will need admin privileges on each machine that you are trying to connect to. You may be able to scale that back, but it will help with troubleshooting.
Look into PowerShell as well as it makes this stuff much easier with WinRM.
What will we do if some machines are 64bit and also systems are . Becouse it searches 32 bit systems ,isn't? It says : "SELECT * FROM Win32_OperatingSystem"
精彩评论