RE: [PHP] Hardware Detection

2005-08-23 Thread Daevid Vincent
This works on Linux/Unix boxen. On windows... You're on your own.


//generate the global array here so we can re-use it independant of output
format
$device['os_ver'] = exec(/bin/uname -a);

$temp = preg_split(/\s+/,exec(/sbin/ifconfig -a eth0 | /bin/grep
HWaddr), -1, PREG_SPLIT_NO_EMPTY);
$device['MAC_addr_eth0'] = $temp[4];

$temp = preg_split(/[\s:]+/,exec(/sbin/ifconfig -a eth0 | /bin/grep
\inet addr:\), -1, PREG_SPLIT_NO_EMPTY);
$device['dot_quad_ip_eth0'] = $temp[2];

$temp = preg_split(/\s+/,exec(/sbin/ifconfig -a eth1 21 | /bin/grep
HWaddr), -1, PREG_SPLIT_NO_EMPTY);
$device['MAC_addr_eth1'] = $temp[4];

$temp = preg_split(/[\s:]+/,exec(/sbin/ifconfig -a eth1 21 | /bin/grep
\inet addr:\), -1, PREG_SPLIT_NO_EMPTY);
$device['dot_quad_ip_eth1'] = $temp[2];

# look at /var for now as that seems to be where the bulk of our data is
stored.
$temp = preg_split(/\s+/,exec(/bin/df | /bin/grep hda1), -1,
PREG_SPLIT_NO_EMPTY);
$device['hd_size'] =  $temp[1];
$device['hd_used'] =  $temp[2];

$temp = preg_split(/\s+/,exec(/usr/bin/free | /bin/grep Mem), -1,
PREG_SPLIT_NO_EMPTY);
$device['ram_total'] = $temp[1];
$device['ram_used'] = $temp[2];

$temp = preg_split(/:/,exec(/bin/cat /proc/cpuinfo | /bin/grep 'model
name'), -1, PREG_SPLIT_NO_EMPTY);
$temp1 = preg_split(/\s\s/,ltrim($temp[1]), -1, PREG_SPLIT_NO_EMPTY);
$device['cpu_type'] = $temp1[0];
$temp = preg_split(/:/,exec(/bin/cat /proc/cpuinfo | /bin/grep 'cpu
MHz'), -1, PREG_SPLIT_NO_EMPTY);
$device['cpu_mhz'] = ltrim($temp[1]);

$temp = preg_split(/:/,substr(exec(/usr/bin/lspci | grep 'VGA'), 8), -1,
PREG_SPLIT_NO_EMPTY);
$device['video'] = $temp[1];

$temp = preg_split(/:/,substr(exec(/usr/bin/lspci | grep 'Host'), 8),
-1, PREG_SPLIT_NO_EMPTY);
$device['mobo'] = $temp[1];

$ethernet = `/usr/bin/lspci | grep 'Ethernet'`;
$temp = split(\n,$ethernet);
$temp1 = preg_split(/:/,substr($temp[0],8), -1, PREG_SPLIT_NO_EMPTY);
$device['nic_eth0'] = substr($temp1[1],1);
$temp1 = preg_split(/:/,substr($temp[1],8), -1, PREG_SPLIT_NO_EMPTY);
$device['nic_eth1'] = substr($temp1[1],1);

$device['proc_count'] = trim(`ps auxw | wc -l`);

$device['someprocessd'] = trim(`ps axuw | grep someprocessd | grep -v
grep | wc -l`);

# Returns the uptime of a Linux system by parsing through /proc/uptime. 
# It returns a 4-field array (days, hours, minutes, seconds). 
# I typically use it like: 
# $ut = linuxUptime(); 
# echo Time since last reboot: $ut[0] days, $ut[1] hours, $ut[2] minutes; 
$ut = strtok( exec(  cat /proc/uptime ),  . ); 
$days = sprintf(  %d, ($ut/(3600*24)) ); 
$hours = sprintf(  %2d, ( ($ut % (3600*24)) / 3600) ); 
$min = sprintf(  %2d, ($ut % (3600*24) % 3600)/60  ); 
$sec = sprintf(  %2d, ($ut % (3600*24) % 3600)%60  ); 
$device['uptime'] = $days.d .$hours.h .$min.m .$sec.s;

//this version fails if the uptime is  24 hours or 1 day since it's shown
as 20:15
//$temp = preg_split(/:/,exec(uptime), -1, PREG_SPLIT_NO_EMPTY);
//$device['loadavg'] = substr($temp[2],1);
preg_match(/load average: (.*)/,exec(uptime), $temp);
$device['loadavg'] = $temp[1];

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Hardware Detection

2005-08-23 Thread Daevid Vincent
I misread the OP. 

No. you can't get information on the hardware of a CLIENT's machine via PHP.
You may be able to do it through some JS or I'm pretty sure through some
ActiveX control (on Microsoft brosers of course). 

We make an appliance that phones home for updates and such, and therefore
we have the luxury of a PHP crontab script that sends this information back
to us. To us, they are clients -- different definition of client than the
OP though. ;-)

 -Original Message-
 From: Daevid Vincent [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, August 23, 2005 1:25 PM
 To: php-general@lists.php.net
 Cc: 'Saenal M'
 Subject: RE: [PHP] Hardware Detection
 
 This works on Linux/Unix boxen.  
 
 //generate the global array here so we can re-use it 
 independant of output format
 $device['os_ver'] = exec(/bin/uname -a);
 
 $temp = preg_split(/\s+/,exec(/sbin/ifconfig -a eth0 | /bin/grep
 HWaddr), -1, PREG_SPLIT_NO_EMPTY);
 $device['MAC_addr_eth0'] = $temp[4];
 
 $temp = preg_split(/[\s:]+/,exec(/sbin/ifconfig -a eth0 | /bin/grep
 \inet addr:\), -1, PREG_SPLIT_NO_EMPTY);
 $device['dot_quad_ip_eth0'] = $temp[2];
 
 $temp = preg_split(/\s+/,exec(/sbin/ifconfig -a eth1 21 
 | /bin/grep
 HWaddr), -1, PREG_SPLIT_NO_EMPTY);
 $device['MAC_addr_eth1'] = $temp[4];
 
 $temp = preg_split(/[\s:]+/,exec(/sbin/ifconfig -a eth1 
 21 | /bin/grep
 \inet addr:\), -1, PREG_SPLIT_NO_EMPTY);
 $device['dot_quad_ip_eth1'] = $temp[2];
 
 # look at /var for now as that seems to be where the bulk of 
 our data is
 stored.
 $temp = preg_split(/\s+/,exec(/bin/df | /bin/grep hda1), -1,
 PREG_SPLIT_NO_EMPTY);
 $device['hd_size'] =  $temp[1];
 $device['hd_used'] =  $temp[2];
 
 $temp = preg_split(/\s+/,exec(/usr/bin/free | /bin/grep Mem), -1,
 PREG_SPLIT_NO_EMPTY);
 $device['ram_total'] = $temp[1];
 $device['ram_used'] = $temp[2];
 
 $temp = preg_split(/:/,exec(/bin/cat /proc/cpuinfo | 
 /bin/grep 'model
 name'), -1, PREG_SPLIT_NO_EMPTY);
 $temp1 = preg_split(/\s\s/,ltrim($temp[1]), -1, 
 PREG_SPLIT_NO_EMPTY);
 $device['cpu_type'] = $temp1[0];
 $temp = preg_split(/:/,exec(/bin/cat /proc/cpuinfo | /bin/grep 'cpu
 MHz'), -1, PREG_SPLIT_NO_EMPTY);
 $device['cpu_mhz'] = ltrim($temp[1]);
 
 $temp = preg_split(/:/,substr(exec(/usr/bin/lspci | grep 
 'VGA'), 8), -1,
 PREG_SPLIT_NO_EMPTY);
 $device['video'] = $temp[1];
 
 $temp = preg_split(/:/,substr(exec(/usr/bin/lspci | grep 
 'Host'), 8),
 -1, PREG_SPLIT_NO_EMPTY);
 $device['mobo'] = $temp[1];
 
 $ethernet = `/usr/bin/lspci | grep 'Ethernet'`;
 $temp = split(\n,$ethernet);
 $temp1 = preg_split(/:/,substr($temp[0],8), -1, 
 PREG_SPLIT_NO_EMPTY);
 $device['nic_eth0'] = substr($temp1[1],1);
 $temp1 = preg_split(/:/,substr($temp[1],8), -1, 
 PREG_SPLIT_NO_EMPTY);
 $device['nic_eth1'] = substr($temp1[1],1);
 
 $device['proc_count'] = trim(`ps auxw | wc -l`);
 
 $device['someprocessd'] = trim(`ps axuw | grep someprocessd 
 | grep -v
 grep | wc -l`);
 
 # Returns the uptime of a Linux system by parsing through 
 /proc/uptime. 
 # It returns a 4-field array (days, hours, minutes, seconds). 
 # I typically use it like: 
 # $ut = linuxUptime(); 
 # echo Time since last reboot: $ut[0] days, $ut[1] hours, 
 $ut[2] minutes; 
 $ut = strtok( exec(  cat /proc/uptime ),  . ); 
 $days = sprintf(  %d, ($ut/(3600*24)) ); 
 $hours = sprintf(  %2d, ( ($ut % (3600*24)) / 3600) ); 
 $min = sprintf(  %2d, ($ut % (3600*24) % 3600)/60  ); 
 $sec = sprintf(  %2d, ($ut % (3600*24) % 3600)%60  ); 
 $device['uptime'] = $days.d .$hours.h .$min.m .$sec.s;
 
 //this version fails if the uptime is  24 hours or 1 day 
 since it's shown
 as 20:15
 //$temp = preg_split(/:/,exec(uptime), -1, PREG_SPLIT_NO_EMPTY);
 //$device['loadavg'] = substr($temp[2],1);
 preg_match(/load average: (.*)/,exec(uptime), $temp);
 $device['loadavg'] = $temp[1];

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Hardware Detection

2005-08-22 Thread Rory Browne
Assuming that you are running a web app then, I concour with Richard. 

If however you are talking about a client in a more traditional sense,
in that you have a specific client application, then that client
application could get the computers hard disk, in the same way as any
other application could.

In Linux, they can simply parse files like /proc/cpuinfo, or something
like that.

Why exactly do you want to do this?

On 8/22/05, Richard Lynch [EMAIL PROTECTED] wrote:
 On Fri, August 19, 2005 9:55 pm, Saenal M wrote:
  Can we get information about hardware on client's PC. (e.g. hard disk,
  processor, keyboard, etc).? And How?
  anyone knows? please reply back.
 
 Not only is it not possible, most of that information is NONE OF YOUR
 DAMN BUSINESS!!! :-)
 
 You can assume that if the browser is sending the headers to indicate
 that I prefer French, then I probably have a keyboard that makes
 French characters.
 
 --
 Like Music?
 http://l-i-e.com/artists.htm
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Hardware Detection

2005-08-21 Thread Richard Lynch
On Fri, August 19, 2005 9:55 pm, Saenal M wrote:
 Can we get information about hardware on client's PC. (e.g. hard disk,
 processor, keyboard, etc).? And How?
 anyone knows? please reply back.

Not only is it not possible, most of that information is NONE OF YOUR
DAMN BUSINESS!!! :-)

You can assume that if the browser is sending the headers to indicate
that I prefer French, then I probably have a keyboard that makes
French characters.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Hardware Detection

2005-08-20 Thread Burhan Khalid

Saenal M wrote:

Hi,

Can we get information about hardware on client's PC. (e.g. hard disk, 
processor, keyboard, etc).? And How?

anyone knows? please reply back.


No, this is not possible with PHP.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Hardware Detection

2005-08-19 Thread Saenal M

Hi,

Can we get information about hardware on client's PC. (e.g. hard disk, 
processor, keyboard, etc).? And How?

anyone knows? please reply back.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php