Click here to Skip to main content
12,509,640 members (54,435 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows C#4.0 Remoting
hi
I have a requirement that i need to find the computer name,Operating System name,MAC address and network role of a given IP address.I am able to find the Computer name but unable to find MAC address and OS information so please advice me how do i do that thanks in advance.

Regards
Prafulla
Posted 27-May-12 21:40pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

To get IP Address:
private static string GetIpAddress()
       {
           string strHostName = "";
           strHostName = System.Net.Dns.GetHostName();
           IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
           IPAddress[] addr = ipEntry.AddressList;
           return addr[addr.Length - 1].ToString();
       }


To get MAC ID:
private string GetMac()
{
    string Mac = string.Empty;
    ManagementClass MC = new ManagementClass("Win32_NetworkAdapter");
    ManagementObjectCollection MOCol = MC.GetInstances();
    foreach (ManagementObject MO in MOCol)
        if (MO != null)
        {
           if (MO["MacAddress"] != null)
                    {
                         Mac = MO["MACAddress"].ToString();
                         if (Mac != string.Empty)
                             break;
                    }
        }
    return Mac;
}

To get Operating System:
private string GetOSName()
{
    System.OperatingSystem os = System.Environment.OSVersion;
    string osName = "Unknown";
 

    switch (os.Platform)
    {
        case System.PlatformID.Win32Windows:
            switch (os.Version.Minor)
            {
                case 0:
                    osName = "Windows 95";
                    break;
                case 10:
                    osName = "Windows 98";
                    break;
                case 90:
                    osName = "Windows ME";
                    break;
            }
            break;
        case System.PlatformID.Win32NT:
            switch (os.Version.Major)
            {
                case 3:
                    osName = "Windws NT 3.51";
                    break;
                case 4:
                    osName = "Windows NT 4";
                    break;
                case 5:
                    if (os.Version.Minor == 0)
                        osName = "Windows 2000";
                    else if (os.Version.Minor == 1)
                        osName = "Windows XP";
                    else if (os.Version.Minor == 2)
                        osName = "Windows Server 2003";
                    break;
                case 6:
                    osName = "Windows Vista";
                    break;
            }
            break;
    }
 
    return osName + ", " + os.Version.ToString();
}
Also refer: OS Name, Version & Product Type[^]

To get Computer Name:
static string GetName ()
{
   string netBiosName = System.Environment.MachineName;
 
   //return netBiosName;
   // Following method is deprecated
   // string dnsName =
   //     System.Net.Dns.GetHostByName("LocalHost").HostName;

   string dnsName = System.Net.Dns.GetHostName();
   return dnsName;
}
Also refer: Similar discussion[^]

Hope I answered all & it helps!
  Permalink  
v2
Comments
Prafulla Sahu 28-May-12 5:01am
   
Thank you very much Prasad for your solution it is useful for me but my requirement is little different,means take one example i have a textbox and we need to enter one IP address of a system among all the system(which are connected in a network(LAN))and based on that IP address we have to find OS information and MAC address will you please help me m stocked any advice will appreciate.

Thank you.
Varsha Venugopal 3-Feb-15 5:57am
   
Sir, good explianation....but I need to get the mac address of virtual machine. i.e. based on ip address. This just gives the system mac address. How to get mac address based on IP and also for virtual machines.
Member 11699255 20-Jun-15 8:29am
   
in which namespace i find managenmentclass
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 28 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100