Recent

Author Topic: [SOLVED] How to detect hardware e.g. CPU name, Video Adapter name, Harddisk name  (Read 1078 times)

Hartmut

  • Sr. Member
  • ****
  • Posts: 419
I have written some small console programs which shall run on 2 different computers and which shall behave a little different on them. Therefore I want to detect, on which hardware a program is running.
Software and operating systems on both computers are identical. To set a different environment variable had to be repeated manually after each copy of PC #1 to PC #2 = uncomfortable. To use a different command line parameter is uncomfortable too (and often I would forget it) => to detect the hardware would be the best way.

The differences between the 2 computers are e.g.:
 - name of CPU
 - name of Video Adapter
 - name of Harddisk
 - name of Mainboard
 - BIOS date
 
How can I read information like this on Ubuntu 18.04? One of them would be enough (I would prefer an easy solution). I use FPC 3.0.4. Thanks in advance.
« Last Edit: May 02, 2020, 10:07:54 am by Hartmut »

TRon

  • Sr. Member
  • ****
  • Posts: 415
cat /proc/cpuinfo ?

I take it you are able to figure out yourself how you can read that without resorting to bash (look for it on the forums) ?

MarkMLl

  • Hero Member
  • *****
  • Posts: 1094
> - name of CPU

lscpu output. Most of that is from the /proc tree but it does add value.

> - name of Video Adapter

lspci output and parsing /var/log/Xorg.0.log, with the caveat that the content of the latter might change (a lot) with distro version.

> - name of Harddisk

Most of this will only be visible to root, but lsblk might help. Might be some useful stuff in /sys/class/block

> - name of Mainboard

Possibly via snmp, otherwise look again at lspci output.

> - BIOS date

Likely to be in dmesg output, but that will be accessible to root only.

HTH.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

winni

  • Hero Member
  • *****
  • Posts: 1605
Hi!

name of CPU:
/proc/cpuinfo contains the number of CPUs, the vendor and the model name

name of Harddisk:
/proc/scsi/scsi contains the vendor and model name of all attached drives: HD, CD/DVD, SDD

The files in the /proc directory ar readable for everybody.

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 1094
name of Harddisk:
/proc/scsi/scsi contains the vendor and model name of all attached drives: HD, CD/DVD, SDD

You can no longer rely on that being present.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

winni

  • Hero Member
  • *****
  • Posts: 1605

You can no longer rely on that being present.

MarkMLl

Hi!

Where is that information written?
That is new to me.

Winni

avra

  • Hero Member
  • *****
  • Posts: 1937
    • Additional info
I want to detect, on which hardware a program is running.
If your goal is software protection, then you might want to take a look at https://wiki.freepascal.org/OnGuard
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 1094

You can no longer rely on that being present.

MarkMLl

Hi!

Where is that information written?
That is new to me.

Winni

GOK, but that particular tree started being deprecated at about the time that IDE discs were moved onto the SCSI subsystem with e.g. a change in the way the buses could be forcibly rescanned to detect hotplugged devices.

The system in front of me- SATA+md on kernel 4.19- doesn't have it, neither do a couple of servers I've just checked, neither does an older system on Debian "Jessie" with 3.16. I don't think I've got anything to hand with "real" SCSI to check, but even there the functionality's been changing since (finger-in-air guess) somewhere around 2.6.

Obviously during that progression things have been added like the /dev/disk tree, but I'm not really sure whether that helps OP since he was specifically asking for identifying/diagnostic info rather than just UUIDs or stuff that was likely to change if a program was moved around.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Hartmut

  • Sr. Member
  • ****
  • Posts: 419
Thank you very much for all of this information. I'm a beginner on Linux to this hardware stuff and with your infos I did a lot of interesting experiments and learned a lot.

My solution is to read file '/proc/cpuinfo' directly to get the name of the CPU. That was the easiest way for me.

lucamar

  • Hero Member
  • *****
  • Posts: 2965
Most of the information you want can be parsed out from the output of lshw -short. For example on this machine it gives me:

Code: Text  [Select][+][-]
  1. [... among other things ...]
  2.  
  3. /0/4                            processor      Mobile Intel(R) Pentium(R) 4 CPU 3.06GHz
  4. /0/100/1/5                      display        RS250 [Mobility Radeon 7000 IGP]
  5. /0/100/14.1/0      /dev/sda     disk           160GB WDC WD1600BEVE-0
  6. /0/100/14.1/1      /dev/cdrom3  disk           DVD-RAM UJ-820S
  7.  
  8. [... and lots more like it ...]

There are other (installable) "lsXXX" commands that can give you other and/or extended information; to see which you have type in a terminal:
Code: [Select]
apropos ^lsThat should give you a list of all commands starting with "ls" for which a man page exists.
« Last Edit: May 02, 2020, 10:56:12 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1094
Most of the information you want can be parsed out from the output of lshw -short. For example on this machine it gives me:

Not on Debian by default. Can't speak for Ubuntu.

OP: note that the CPU/core numbers in /proc/cpuinfo are architecture-specific, and might not be contiguous.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

TRon

  • Sr. Member
  • ****
  • Posts: 415
How can I read information like this on Ubuntu 18.04? One of them would be enough (I would prefer an easy solution). I use FPC 3.0.4. Thanks in advance.

So any one  ;-p proposed will do.

Just run a checksum over one of the proposals and it would be enough for TS to distinguish between two machines. Reading a user of app directory contents would probably be enough. Or free diskspace or a random pixel on the desktop for that matter :-)

lucamar

  • Hero Member
  • *****
  • Posts: 2965
Not on Debian by default. Can't speak for Ubuntu.

Oops! You're right; after a closer look it seems it's one of the utils I install on auto-pilot after setting up a new system, so it's on all my systems :-[
« Last Edit: May 02, 2020, 10:57:15 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 1605

You can no longer rely on that being present.

MarkMLl

Hi!

Where is that information written?
That is new to me.

Winni

GOK, but that particular tree started being deprecated at about the time that IDE discs were moved onto the SCSI subsystem with e.g. a change in the way the buses could be forcibly rescanned to detect hotplugged devices.

The system in front of me- SATA+md on kernel 4.19- doesn't have it, neither do a couple of servers I've just checked, neither does an older system on Debian "Jessie" with 3.16. I don't think I've got anything to hand with "real" SCSI to check, but even there the functionality's been changing since (finger-in-air guess) somewhere around 2.6.

Obviously during that progression things have been added like the /dev/disk tree, but I'm not really sure whether that helps OP since he was specifically asking for identifying/diagnostic info rather than just UUIDs or stuff that was likely to change if a program was moved around.

MarkMLl


Hi!

I use the Kernel 5.6.6-1 since some days and the information in /proc is as above shown.

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 1094
I use the Kernel 5.6.6-1 since some days and the information in /proc is as above shown.

Winni

It will be distro-specific, and depend on how the kernel is configured and/or what modules are loaded. See e.g. https://serverfault.com/questions/236711/where-is-proc-scsi-scsi-in-debian-6

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

 

TinyPortal © 2005-2018