How to programmatically check the operating system of the remote host?

advertisements

I need to check if remote host is Windows or Unix/Linux. I can't assume that it has web server configured. All I can do is to try to connect to several TCP or UDP services.

Which TCP services (TCP port numbers) usually will be opened on Windows and not on Unix/Linux and vise versa?

The other way is to try to ssh to it, and if it fails assume that it Windows host. The problem is, that I need this in order to choose the remote access method ssh or something Windows friendly like psexec.


You can read the output of nmap to detect which OS a remote host is running. It has a whole module dedicated to this. Here is a guide to using it.