0

Is there any way to get the exact OS name for all type of devices connected to the same network. Currently I'm using the below approach.

Ping p = new Ping();
PingReply result = p.Send(ip, 200);
if (result.Options.Ttl == 64)
{
   osName = "Linux/Unix/Android";
}
else if (result.Options.Ttl == 128)
{
  osName = "Windows";
}
else
{
  osName = "Solaris/AIX";
}
riQQ
  • 9,878
  • 7
  • 49
  • 66
CodeHawk
  • 1
  • 1

1 Answers1

0

You can use Nmap for that with the option -O for OS detection (see remote OS detection in python).

For .NET, you can use this Nmap wrapper library https://github.com/thomdixon/SaltwaterTaffy, f.e. It requires you to have Nmap installed and it being in your path.

using SaltwaterTaffy;
using SaltwaterTaffy.Container;
using System;

namespace ScanNetwork
{
    class Program
    {
        public static void Main(string[] args)
        {
            // target can be a string, an IPAddress or an IEnumerable of either
            var target = new Target("192.168.0.0/24");
            var scanner = new Scanner(target);

            scanner.PersistentOptions = new NmapOptions {
                NmapFlag.OsDetection
            };
            var hosts = scanner.HostDiscovery();
            foreach (var host in hosts)
            {
                Console.WriteLine(host.Address);
                foreach(var osMatch in host.OsMatches)
                {
                    Console.WriteLine($"{osMatch.Name} ({osMatch.Family} {osMatch.Generation}) [{osMatch.Certainty}]");
                }

            }
        }
    }
}
riQQ
  • 9,878
  • 7
  • 49
  • 66