如何发现机器类型?

发布于 2024-07-11 20:49:01 字数 473 浏览 4 评论 0原文

我想发现大量机器的机器架构类型。 我有每台机器的主机名。 这些机器有 Debian 4 linux、SunOS 9、SunOS 10 或 Apple Darwin。 所有这些都类似于 UNIX,但有细微的差别。

我想知道: - 架构(x86、x86_64、ia64、sparc、powerpc...) - 处理器类型(英特尔奔腾、奔腾 ​​Pro、奔腾 II、sparc、powerpc、itanium、athlon、core 2 duo、cytrix 等) - 处理器数量

注意,我想要机器的“类​​型”。 使用“uname”的愚蠢方法在 Sun 上不起作用,当机器实际上是“x86_64”但操作系统是 32 位时,它还会返回“i686”之类的内容。 /proc/cpuinfo 也不起作用,事情变得更加复杂,因为有些机器没有安装 C 编译器(我确信它们都有 sh,也许是 python 或 perl,不知道)。

提前致谢!! :)

I would like to discover the machine architecture type of a big number of machines. I have the hostname of each machine. The machines have Debian 4 linux, SunOS 9, SunOS 10 or Apple Darwin. All are unix-like, but with minor differences.

I would like to know:
- architecture (x86, x86_64, ia64, sparc, powerpc...)
- processor type (intel pentium, pentium pro, pentium II, sparc, powerpc, itanium, athlon, core 2 duo, cytrix, etc...)
- number of processors

Beware, I want the "type" of the machine. The stupid approach using 'uname' does not work on Sun and it also returns things like 'i686' when the machine is in fact 'x86_64' but the operating system is 32 bits. /proc/cpuinfo doesn't work neither, and things get even more complicated because some machines dont have a C compiler installed (I'm sure they all have sh, perhaps python or perl, dunno).

Thanks in advance!! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

苍暮颜 2024-07-18 20:49:02

拱形; uname -a

arch 是获取 CPU 指令集名称的标准方法。 uname -a 获取大量有关操作系统的信息。 uname 不带 a 获取操作系统名称。

然而从编程角度来说,arch 的等价物是 uname -m

arch ; uname -a

arch is the standard way to get the name of the CPU instruction set. uname -a gets a bunch of stuff about the OS. uname withouth the a gets the OS name.

However programmatically speaking, the equivalent to arch is uname -m.

过期以后 2024-07-18 20:49:02

您可以尝试以下 Perl 一行:

perl -MConfig -e 'print "$Config{myarchname}\n";'

我知道在带有 Perl 5.10.0 的 Mac OS X Leopard 上它会打印“i386-darwin”。 我不知道 Perl 中有什么方法可以获取实际的处理器名称 - 你最好的选择可能是 C,因为它的可能性相当有限。 您可以从 Perl 获取 C 编译器的预定义宏:

perl -MConfig -e 'print join("\n", split(/ /, $Config{cppsymbols})), "\n";'

这将列出 C 宏,例如 Mach-O 格式的 __LITTLE_ENDIAN____MACH__ 以及 __i386__ (至少在 Leopard 上),以及像 __GNUC____STDC__ 这样无用的。 当然,所有这些帮助都假设您在所有机器上都安装了 Perl。 如果没有,我相信其他语言也有类似的工具可以帮助您。

You can try the following Perl one-liner:

perl -MConfig -e 'print "$Config{myarchname}\n";'

I know on Mac OS X Leopard with Perl 5.10.0 it prints "i386-darwin". I don't know of a way in Perl to get the actual processor name - your best bet is probably C since it's a fairly limited set of possibilities. You can get at a C compiler's predefined macros from Perl:

perl -MConfig -e 'print join("\n", split(/ /, $Config{cppsymbols})), "\n";'

This will list C macros like __LITTLE_ENDIAN__ and __MACH__ for Mach-O format and __i386__ (on Leopard at least), as well as the useless ones like __GNUC__ and __STDC__. Of course, all of this help assumes you have Perl on all machines. If not, I'm sure other languages have similar facilities to help you.

甜妞爱困 2024-07-18 20:49:02

我建议你看看 Puppet 系统的 Factor 组件。 来自 URL http://reducinglabs.com/projects/facter/

用于从操作系统检索事实的跨平台 Ruby 库。 支持多种解析机制,其中任何一种都可以限制为仅在某些操作系统或环境上运行。 Facter 对于检索操作系统名称、IP 地址、MAC 地址和 SSH 密钥等信息特别有用。

I would suggest you look at the facter component of the Puppet system. From the URL http://reductivelabs.com/projects/facter/.

A cross-platform Ruby library for retrieving facts from operating systems. Supports multiple resolution mechanisms, any of which can be restricted to working only on certain operating systems or environments. Facter is especially useful for retrieving things like operating system names, IP addresses, MAC addresses, and SSH keys.

奶气 2024-07-18 20:49:02

为什么 /proc/cpuinfo 不起作用?

我不知道你提到的所有操作系统,但我认为它提供了 Linux 下相当详细的信息。 至少,通过CPU的型号,可以从数据表中查到其他信息。

软件只能看到操作系统让它看到的内容,因此如果操作系统不提供 /proc/cpuinfo 等信息,那么您将无法知道它。

回复评论:

我并不是说为所有操作系统查找 /proc/cpuinfo 。 这是一个两步方法:首先找出它正在使用 uname 的操作系统,然后查找 cpu 信息的操作系统特定位置。

Why /proc/cpuinfo doesn't work?

I don't know all of the OSs you mentioned, but I think it give quite detailed information under Linux. At least, with the model of CPU, other informations can be looked up from a data table.

The software can only see what the OS let it to see, so if the OS doesn't provide informations like /proc/cpuinfo, then you'll have no way to know it.

reply to the comments:

I am not saying look for /proc/cpuinfo for all the OS. It's a two steps method: first you find out which OS it is using uname, then look for the OS specific position for the cpu info.

怪我鬧 2024-07-18 20:49:02

这不是完整的答案,但它可能会帮助您实现目标。

正如您提到的,arch 不适用于 HP-UX Itanium,并且它没有 /proc 文件系统。

这个 解释了如何通过 shell 命令简单地确定操作系统使用的字节顺序(字节顺序)。 它至少适用于 4 个主要 Unix(Linux x86_64、Solaris Sparc、AIX/Power、HP-UX Itanium)。 如果您知道字节顺序,您可以根据 this< 推断出您正在处理的 CPU 的很多信息/a> 来源。

例如,如果 Solaris 不会告诉您正确的体系结构,但您看到它是大端字节序,那么您至少知道您不在 x86_64 上,并且可能不在 Sparc 上。

最后,对于 Sparc,您可以执行以下操作来确定操作系统是在 32 位模式还是 64 位模式下运行:

# isalist -v
sparcv9+vis2 sparcv9+vis sparcv9 sparcv8plus+vis2 sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc

如果显示“sparcv9”,则为 64 位,sparcv8 为 32 位

This is not a complete answer, but it may help you reach your goal.

arch does not work on HP-UX Itanium, and it does not have the /proc filesystem, as you mentioned.

This explains how to determine the endianness (byte order) the O/S is using simply with shell commands. It works on at least 4 major Unixes (Linux x86_64, Solaris Sparc, AIX/Power, HP-UX Itanium). If you know the byte ordering you can deduce a lot about which CPU you're dealing with, based on this source.

For instance, if Solaris won't tell you the correct architecture, but you see that it's big endian, you at least know you're not on x86_64, and probably Sparc.

Finally, for Sparc you can do this to determine whether the OS is running in 32 or 64 bit mode:

# isalist -v
sparcv9+vis2 sparcv9+vis sparcv9 sparcv8plus+vis2 sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc

If it says 'sparcv9' it's 64 bit, sparcv8 is 32

似最初 2024-07-18 20:49:02

使用uname -a会给你带来很多信息,所以你必须搜索你想要的信息。

只需使用:

uname -i

用于硬件平台

uname -m

机器硬件名称

The use of uname -a will bring you to much information, so you have to search for the information you want to have.

Just use:

uname -i

for the hardware platform

or

uname -m

for the machine hardware name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文