Poll multiple desktops/servers on a network remotely to determine the IP Type: Static or DHCP

Posted by Charles Laird on Stack Overflow See other posts from Stack Overflow or by Charles Laird
Published on 2010-03-30T19:17:19Z Indexed on 2010/03/30 19:33 UTC
Read the original article Hit count: 486

Filed under:
|
|
|
|

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.GetPropertyValue("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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about network