如何以编程方式检查远程主机的操作系统?
我需要检查远程主机是 Windows 还是 Unix/Linux。 我不能假设它已配置网络服务器。 我所能做的就是尝试连接到多个 TCP 或 UDP 服务。
哪些 TCP 服务(TCP 端口号)通常会在 Windows 上打开,而不会在 Unix/Linux 上打开,反之亦然?
另一种方法是尝试通过 ssh 连接到它,如果失败,则假定它是 Windows 主机。问题是,我需要这个来选择远程访问方法 ssh 或 Windows 友好的方法,如 psexec。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以读取 nmap 的输出来检测远程主机正在运行哪个操作系统。它有一个专门用于此目的的完整模块。这是使用指南。
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.
为什么不尝试以一种方式连接,如果失败,再以另一种方式连接,如果两者都不起作用,则告诉用户?
如果这就是您想做的全部事情,则无需实际检查操作系统。
Why not just try to connect one way, and if that fails, connect the other way, and if neither work, tell the user?
If that's all you're trying to do, there's no need to actually check the OS.
要以任何程度的确定性回答这个问题都不是一件容易的事情,因为很少有端口始终在一个操作系统上打开,但在另一个操作系统上则不打开。
您可以尝试以下部分/全部
我建议扫描端口范围可能会给您带来麻烦,特别是如果这些不是您的计算机。您可能会发现您的 IP 地址被记录为“端口扫描程序”的可能来源。
网络上有一些相当广泛的可用端口列表。例如 http://keir.net/portlist.html
This is not an easy thing to answer with any degree of certainty as there are very few ports that will always be open on one OS but not on another.
You could try some/all of the following
I would suggest that scanning ranges of ports may lead you into trouble particularly if these are not your machines. You may find your IP address logged as a possible source of "Port Scanners"
There are some fairly extensive lists of ports available on the web. e.g. http://keir.net/portlist.html