~ K A L I ~
UNAME : Linux web65.extendcp.co.uk 4.18.0-553.56.1.el8_10.x86_64 #1 SMP Tue Jun 10 05:00:59 EDT 2025 x86_64SERVER IP : 10.0.187.65 -________-
CLIENT IP : 216.73.216.109 MINI SHELL D ZAB '
Current File : //usr/share/perl5/vendor_perl/HI/Hardware.pm |
package HI::Hardware;
use strict;
use warnings;
use Switch;
use Parse::DMIDecode ();
use XML::Simple;
use HI::Hardware::Dell;
use HI::Hardware::HP;
sub new {
my $class = shift;
my $self = {
DMI => new Parse::DMIDecode( dmidecode => "/usr/sbin/dmidecode" ),
isdell => 0,
ishp => 0,
ismicro => 0
};
bless $self, $class;
$self->{DMI}->probe();
if ( $self->{DMI}->keyword("chassis-manufacturer") =~ /^Dell/ ) {
$self->{isdell} = 1;
$self->{Dell} = new HI::Hardware::Dell;
$| = 1;
}
if ( $self->{DMI}->keyword("chassis-manufacturer") =~ /^HP/ ) {
$self->{ishp} = 1;
$self->{HP} = new HI::Hardware::HP;
$| = 1;
}
if ( $self->{DMI}->keyword("chassis-manufacturer") =~ /^Supermicro/ ) {
$self->{ismicro} = 1;
}
return $self;
}
sub memory {
my $self = shift;
if ( $self->{isdell} ) {
return $self->{Dell}->memory();
}
else {
return $self->DMI_memory();
}
}
sub DMI_memory {
my $self = shift;
my @memory_to_return;
for my $handle ( $self->{DMI}->get_handles( group => "memory" ) ) {
if ( $handle->description eq 'Memory Device' ) {
my $size = $handle->parsed_structures->{Size}[0];
if ( $size eq 'No Module Installed' ) {
#Slot is empty
next;
}
elsif ( $size =~ /^(\d+) MB$/ ) {
push @memory_to_return, $1;
}
else {
warn "Cannot parse $size";
}
}
}
return @memory_to_return;
}
sub vds {
my $self = shift;
if ( $self->{isdell} ) {
return $self->{Dell}->vds();
}
if ( $self->{ishp} ) {
return $self->{HP}->vds();
}
else {
my @vds;
push @vds, $self->software_raid_vds();
push @vds, $self->hardware_raid_vds();
return @vds;
}
}
sub hardware_raid_vds {
my $self = shift;
my @disks_to_return;
$/ = "\n\n\nVirtual Drive: ";
my $i = 0;
open MEGA, '-|', "/usr/sbin/MegaCli -LdInfo -Lall -aall -NoLog" or die $!;
while ( my $span = <MEGA> ) {
#Because the record separator $/ has changed, every loop contains a virtual/logical disk over multiple lines
my @lines = split( /\n/, $span );
my $raid_level;
my $partition = '';
my $size = 0;
foreach (@lines) {
chomp;
if (/^Size\s+:\s([\d\.]+) ([MGT])B$/) {
$size = $1;
switch ($2) {
case 'G' { $size *= 1024 }
case 'T' { $size *= 1024 * 1024; };
}
#printf "Size: %d MB\n", $size;
}
if (/^RAID Level\s+: Primary-(\d+)/) {
$raid_level = $1;
}
if ( defined($raid_level)
&& $raid_level == 1
&& /^Span Depth\s+: (\d+)/ )
{
if ( $1 > 1 ) {
$raid_level = 10;
}
}
if (/Target Id: (\d+)/) {
my $ld_index = $1;
my @potentials = glob(
"/dev/disk/by-path/pci-0000:??:00.0-scsi-?:2:$ld_index:0");
if ( scalar(@potentials) == 1 ) {
my $target = readlink $potentials[0];
if ($target) {
$target =~ s#[^\w]+##;
$partition = $target;
}
}
}
}
#print "Level $raid_level\n";
push @disks_to_return,
{ size_mb => $size, level => $raid_level, partition => $partition };
}
close MEGA;
$/ = "\n";
return @disks_to_return;
}
sub software_raid_vds {
my $self = shift;
my @disks_to_return;
my @mdVols = glob('/dev/md/Volume?');
my @mdPDs;
foreach (@mdVols) {
my $target;
if ( -l $_ ) {
$target = readlink($_);
$target =~ s#[^\w]+##;
}
open MD, '-|', "/sbin/mdadm --export $_" or die $!;
while (<MD>) {
chomp;
my ( $size, $raid_level );
my @parts = split( /\s+/, $_ );
if ( $parts[2] =~ /^raid(\d+)$/ ) {
#print "Raid level $1\n";
$raid_level = $1;
}
if ( $parts[1] =~ /^([\d\.]+)([MGT])iB$/ ) {
$size = $1;
switch ($2) {
case 'G' { $size *= 1024 }
case 'T' { $size *= 1024 * 1024; };
}
}
#printf "%s MiB\n", $size;
push @disks_to_return,
{ size_mb => $size, level => $raid_level, partition => $target };
}
close MD;
}
return @disks_to_return;
}
sub pds {
my $self = shift;
if ( $self->{isdell} ) {
return $self->{Dell}->pds();
}
if ( $self->{ishp} ) {
return $self->{HP}->pds();
}
else {
my @pds;
push @pds, $self->software_raid_pds();
push @pds, $self->hardware_raid_pds();
return @pds;
}
}
sub hardware_raid_pds {
my $self = shift;
my @disks_to_return;
$/ = "\n\n\nEnclosure Device ID: ";
open MEGA, '-|', "/usr/sbin/MegaCli -PDList -a0 -NoLog" or die $!;
while ( my $span = <MEGA> ) {
my @lines = split( /\n/, $span );
my ( $size, $model, $serial );
for (@lines) {
if (/Inquiry/) {
my @parts = split( /:\s+/, $_ );
$parts[1] =~ s/\s+/ /mg;
my @sections = split( /\s/, $parts[1] );
$serial = shift @sections;
$model = join( ' ', @sections );
#printf "Model: %s\n", join(' ', @sections);
#printf "Serial: %s\n", $serial;
}
if (/Raw Size:\s*(\d+\.?\d+)\s+([MGT]B)/) {
$size = $1;
switch ($2) {
case 'GB' { $size *= 1024 }
case 'TB' { $size *= 1024 * 1024; };
}
#printf "Size: %d MB\n", $size;
}
}
push @disks_to_return,
{ size_mb => $size, model => $model, serial => $serial };
}
close MEGA;
$/ = "\n";
return @disks_to_return;
}
sub software_raid_pds {
my $self = shift;
my @disks_to_return;
my @mdVols = glob('/dev/md/Volume?');
my @mdPDs;
foreach (@mdVols) {
open MD, '-|', "/sbin/mdadm --detail --export $_" or die $!;
while (<MD>) {
chomp;
my @parts = split( /=/, $_ );
push @mdPDs, $parts[1] if $parts[0] =~ /DEV$/;
}
close MD;
}
foreach ( sort @mdPDs ) {
my ( $size, $model, $serial );
#print "$_\n";
open HDPARM, '-|', "/sbin/hdparm -I $_" or die $!;
while (<HDPARM>) {
chomp;
next unless /:/;
my @parts = split( /:\s+/, $_ );
if ( $parts[0] =~ /Model Number/ ) {
#printf "Model: %s\n", $parts[1];
$model = $parts[1];
$model =~ s/\s+$//; #Lob off trailing whitespace
}
if ( $parts[0] =~ /Serial Number/ ) {
#printf "Serial: %s\n", $parts[1];
$serial = $parts[1];
}
if ( $parts[0] =~ /device size with M = 1024\*1024/ ) {
my @size = split( /\s+/, $parts[1] );
#printf "Size (MB): %s\n", $size[0];
$size = $size[0];
}
}
close HDPARM;
push @disks_to_return,
{ size_mb => $size, model => $model, serial => $serial };
}
return @disks_to_return;
}
sub interfaces {
my $self = shift;
my @interfaces;
my $dir = '/sys/class/net';
opendir NET, $dir or die $!;
my @contents = readdir(NET) or die $!;
closedir NET;
for ( sort @contents ) {
if ( -l "$dir/$_" ) {
#RHEL6
my $target = readlink("$dir/$_");
next if $target =~ m#devices/virtual/#;
if ( -r "$dir/$target/address" ) {
open INT, '<', "$dir/$target/address";
chomp( my $int = <INT> );
close INT;
push @interfaces, $int;
}
}
elsif ( -d "$dir/$_" ) {
#RHEL4 RHEL5
next unless /^eth/;
open INT, '<', "$dir/$_/address";
chomp( my $int = <INT> );
close INT;
push @interfaces, $int;
}
}
return @interfaces;
}
sub cpus {
my $self = shift;
if ( $self->{isdell} ) {
return $self->{Dell}->cpus();
}
else {
return $self->DMI_cpus();
}
}
sub DMI_cpus {
my $self = shift;
my @cpus;
# Available groups to query: bios, system, baseboard,
#chassis, processor, memory, cache, connector, slot
for my $handle ( $self->{DMI}->get_handles( group => "processor" ) ) {
my $cpu = $handle->parsed_structures->{Version}[0];
$cpu =~ s#\s+# #mg;
push @cpus, $cpu;
}
return @cpus;
}
sub chassis {
my $self = shift;
if ( $self->{isdell} ) {
return $self->{Dell}->chassis();
}
else {
return $self->DMI_chassis();
}
}
sub DMI_chassis {
my $self = shift;
my $chassis = $self->{DMI}->keyword("system-product-name");
my $serial;
if ( $self->{ismicro} ) {
$serial = $self->{DMI}->keyword("baseboard-serial-number");
}
else {
$serial = $self->{DMI}->keyword("system-serial-number");
}
return $chassis, $serial;
}
sub controllers {
my $self = shift;
if ( $self->{isdell} ) {
$self->{Dell}->controllers();
}
if ( $self->{ishp} ) {
$self->{HP}->controllers();
}
else {
$self->MegaCli_controllers();
}
}
sub MegaCli_controllers {
my $self = shift;
my @controllers;
#MegaCli -adpallinfo -aAll
$/ = "\n\n\nAdapter #";
open MEGA, '-|', "/usr/sbin/MegaCli -adpallinfo -aAll -NoLog" or die $!;
while ( my $span = <MEGA> ) {
my @lines = split( /\n/, $span );
for (@lines) {
if (/^Product Name\s+: (.*)/) {
push @controllers, $1;
}
}
}
close MEGA;
$/ = "\n";
return @controllers;
}
1
Coded by KALI :v Greetz to DR HARD ../ kali.zbi@hotmail.com