2

From a .net based application, what would be the quickest way to determine if an OS running on a remote machine is windows or linux?

Faisal
  • 4,054
  • 6
  • 34
  • 55
  • 1
    Are you familiar with WMI..? try doing a google search.. there are several examples out there.. also what have you actually tried and or researched – MethodMan May 08 '13 at 04:27
  • 1
    [WMI Detecting Operating System using C#](http://andrewensley.com/2009/10/c-detect-windows-os-version-%E2%80%93-part-2-wmi/) – MethodMan May 08 '13 at 04:29
  • many links,,, have googled once??? http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net ,, http://bytes.com/topic/perl/answers/943163-how-detect-remote-machine-os-while-connecting ,, http://stackoverflow.com/questions/4682595/how-to-get-remote-machine-os-version-in-net-without-wmi – Freelancer May 08 '13 at 04:30
  • On a remote machine accessible through what? – Andrey Shchekin May 08 '13 at 04:34
  • 1
    @ KRAZE; Freelancer: yes i did some research and already had found the links you two have posted. But none of them solves the problem as almost all of them are assuming that the remote machine is also running windows. Plus WMI is not a reliable solution as its service is not always supposed to be running everywhere. – Faisal May 08 '13 at 04:36
  • Should you be using `C#` then? Seems to me like you need to use something more platform agnostic. – Tejas Sharma May 08 '13 at 04:38
  • yea, I am using C#. And yes i am more interested in OS itself than the actual version of that OS – Faisal May 08 '13 at 04:42
  • @MethodMan That would only work for localhost, not remote machines (specially not if they are not windows) – Cleptus Sep 13 '18 at 08:49

1 Answers1

2

Just ping it. If the TTL (Time-To-Live) is 254 or less it is unix-based and if TTL is 128 or less it is windows.

Farzan
  • 745
  • 10
  • 25
  • I just tried it. For windows I got TTL of 128 while for Linux (fedora), I got 64. Comments? – Faisal May 08 '13 at 04:41
  • Unix-based os starts from 254 and windwos starts from 128 but this value reduces by number of N where N is number of hops between your computer and remote computer. now what is the possibility of having 126 hops between your computer and remote computer? – Farzan May 08 '13 at 04:46
  • For more precise info please refer to: http://www.binbert.com/blog/2009/12/default-time-to-live-ttl-values/ – Farzan May 08 '13 at 04:46
  • nmap is also an open-source project which is capable of detecting remote OS. but it's not c#: http://nmap.org/book/osdetect.html – Farzan May 08 '13 at 04:58
  • You are missing that TTL [can be configured](https://askubuntu.com/questions/667096/how-to-change-the-default-ttl-of-tcp-ip-packets) so it makes it unreliable. @Farzan It could be launched in a process from C# and the output be parsed – Cleptus Sep 13 '18 at 08:50