Home Backend Development PHP Tutorial PHP获取电脑网卡MAC地址

PHP获取电脑网卡MAC地址

Jun 20, 2016 pm 01:04 PM
array ipconfig quot return this

获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址

<?php  <br />    /**  <br />    获取网卡的MAC地址原码;目前支持WIN/LINUX系统  <br />    获取机器网卡的物理(MAC)地址  <br />    **/  <br />        <br />    class GetMacAddr{  <br />        <br />            var $return_array = array(); // 返回带有MAC地址的字串数组  <br />            var $mac_addr;  <br />        <br />            function GetMacAddr($os_type){  <br />                 switch ( strtolower($os_type) ){  <br />                          case "linux":  <br />                                    $this->forLinux();  <br />                                    break;  <br />                          case "solaris":  <br />                                    break;  <br />                          case "unix":  <br />                                     break;  <br />                           case "aix":  <br />                                     break;  <br />                           default:  <br />                                     $this->forWindows();  <br />                                     break;  <br />         <br />                  }  <br />         <br />                    <br />                  $temp_array = array();  <br />                  foreach ( $this->return_array as $value ){  <br />         <br />                            if (  <br />    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,  <br />    $temp_array ) ){  <br />                                     $this->mac_addr = $temp_array[0];  <br />                                     break;  <br />                           }  <br />         <br />                  }  <br />                  unset($temp_array);  <br />                  return $this->mac_addr;  <br />             }  <br />         <br />         <br />             function forWindows(){  <br />                  @exec("ipconfig /all", $this->return_array);  <br />                  if ( $this->return_array )  <br />                           return $this->return_array;  <br />                  else{  <br />                           $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";  <br />                           if ( is_file($ipconfig) )  <br />                              @exec($ipconfig." /all", $this->return_array);  <br />                           else  <br />                              @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);  <br />                           return $this->return_array;  <br />                  }  <br />             }  <br />         <br />         <br />         <br />             function forLinux(){  <br />                  @exec("ifconfig -a", $this->return_array);  <br />                  return $this->return_array;  <br />             }  <br />         <br />    }  <br />//方法使用<br />$mac = new GetMacAddr(PHP_OS);  <br />echo $mac->mac_addr;  <br />?>
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to use the array_combine function in PHP to combine two arrays into an associative array How to use the array_combine function in PHP to combine two arrays into an associative array Jun 26, 2023 pm 01:41 PM

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values ​​of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

Simple and clear method to use PHP array_merge_recursive() function Simple and clear method to use PHP array_merge_recursive() function Jun 27, 2023 pm 01:48 PM

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values ​​of the same keys, making the program design more flexible. array_merge

How to execute the ipconfig command How to execute the ipconfig command Feb 19, 2024 pm 07:47 PM

How to run the ipconfig command In a computer network, IP (Internet Protocol) is a protocol used to transmit data in the network. IP addresses are used to identify devices on the network, and the ipconfig running command is a tool used to obtain and manage network connection information. In Windows operating systems, the ipconfig command is very commonly used and very simple to use. To run the ipconfig command, just follow these simple steps: Step 1: Open the command prompt

How does Vue3 use setup syntax sugar to refuse to write return How does Vue3 use setup syntax sugar to refuse to write return May 12, 2023 pm 06:34 PM

Vue3.2 setup syntax sugar is a compile-time syntax sugar that uses the combined API in a single file component (SFC) to solve the cumbersome setup in Vue3.0. The declared variables, functions, and content introduced by import are exposed through return, so that they can be used in Vue3.0. Problems in use 1. There is no need to return declared variables, functions and content introduced by import during use. You can use syntactic sugar //import the content introduced import{getToday}from'./utils'//variable constmsg='Hello !'//function func

See all articles