PHP gets the computer's unique identifier [CPU, Nic]

Source: Internet
Author: User

The following is reproduced from the Internet source code, but I test can not be carried out, do not know how, turn around you can exchange

<?php
Get CPU information from your computer
function Onlyu () {
$a = ";
$b = Array ();
if (function_exists (' exec ')) {
if (Mailto:[email protected] (/all ", $b)) {
return false;
}
}elseif (function_exists (' system ')) {
Ob_start ();
if (Mailto:[email protected] (/all ")) {
return false;
}else{
//...
}
$b = Ob_get_contents ();
Ob_end_clean ();
$b = explode ("\ n", $b);//print_r ($b);
Array_pop ($b);
}else{
return false;
}
$all = sizeof ($b);
for ($i = 0; $i < $all; $i + +) {
if (Strpos ($b [$i], "Description")!== false) {
if (Strpos ($b [$i +1], "physical Address")!== false) {
$c = Explode (":", $b [$i +1]);
$a = Trim ($c [1]);
Break
}
}
}
return empty ($a) false: $a;
}
Get the address of the MAC for the NIC
function Getmac () {
@exec ("Ipconfig/all", $array);
for ($Tmpa; $Tmpa <count ($array); $Tmpa + +) {
if (eregi ("Physical", $array [$Tmpa])) {
$mac =explode (":", $array [$Tmpa]);
return $mac [1];
}
}
}
Echo Onlyu ();
Echo Getmac ();
?>

Get the address of the MAC for the NIC
<?php
Class Getmacaddr
{
var $return _array = Array (); Returns an array of strings with MAC addresses
var $mac _addr;
function getmacaddr ($os _type)
{
Switch (Strtolower ($os _type))
{
Case "Linux":
$this-Forlinux ();
Break
Case "Solaris":
Break
Case "UNIX":
Break
Case "AIX":
Break
Default
$this-forwindows ();
Break
}
$temp _array = Array ();
foreach ($this-Return_array as $value)
{
if (Preg_match ("/[0-9a-f][0-9a-f][:-]". " [0-9a-f] [0-9a-f] [:-] ". " [0-9a-f] [0-9a-f] [:-] ". " [0-9a-f] [0-9a-f] [:-] ". " [0-9a-f] [0-9a-f] [:-] ". " [0-9a-f] [0-9a-f]/i ", $value, $temp _array)) {
$this-mac_addr = $temp _array[0];
Break
}
}
unset ($temp _array);
return $this, mac_addr;
}
function Forwindows ()
{
@exec ("Ipconfig/all", $this-Return_array);
if ($this-Return_array) {
return $this, Return_array;
}else{
$ipconfig = $_server["windir"]. " \system32\ipconfig.exe ";
if (Is_file ($ipconfig)) {
@exec ($ipconfig. "/all", $this-Return_array);
}else{
@exec ($_server["windir"]. " \system\ipconfig.exe/all ", $this-Return_array);
}
return $this, Return_array;
}
}
function Forlinux ()
{
@exec ("Ifconfig-a", $this-Return_array);
return $this, Return_array;
}
}
$mac = new Getmacaddr (php_os);
Echo $mac-mac_addr;
?>

PHP gets the computer's unique identifier [CPU, Nic]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.