{"id":727,"date":"2023-01-26T14:17:19","date_gmt":"2023-01-26T06:17:19","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=727"},"modified":"2024-07-08T12:43:35","modified_gmt":"2024-07-08T04:43:35","slug":"php-%e8%8e%b7%e5%8f%96%e6%9c%8d%e5%8a%a1%e7%ab%afmac%e5%9c%b0%e5%9d%80","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2023\/01\/26\/php-%e8%8e%b7%e5%8f%96%e6%9c%8d%e5%8a%a1%e7%ab%afmac%e5%9c%b0%e5%9d%80\/","title":{"rendered":"php \u83b7\u53d6\u670d\u52a1\u7aefMAC\u5730\u5740"},"content":{"rendered":"<pre class=\"lang:default decode:true\">\/**\n     * \u83b7\u53d6MacAddress\n     * @var array\n     *\/\n    public $returnArray = [];\n    public $macAddress;\n\n    public function getMacAddress($os_type)\n    {\n        switch (strtolower($os_type)) {\n            \/\/ MacOS MoJave\u7cfb\u7edf\uff08\u5904\u7406\u540clinux\uff09\n            case \"darwin\":\n            case \"linux\":\n                $this-&gt;forLinux();\n                break;\n            case \"solaris\":\n                break;\n            case \"unix\":\n                break;\n            case \"aix\":\n                break;\n            default:\n                $this-&gt;forWindows();\n                break;\n\n        }\n        $tempArray = [];\n        foreach ($this-&gt;returnArray as $value) {\n            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, $tempArray)) {\n                $this-&gt;macAddress = $tempArray[0];\n                break;\n            }\n\n        }\n        unset($tempArray);\n        return $this-&gt;macAddress;\n    }\n\n    \/**\n     * \u83b7\u53d6ipconfig \/all \u6bcf\u884c\u53c2\u6570\u8f6c\u5316\u4e3a\u6570\u7ec4\n     * @return array\n     *\/\n    public function forWindows()\n    {\n        @exec(\"ipconfig \/all\", $this-&gt;returnArray);\n        if ($this-&gt;returnArray) {\n            return $this-&gt;returnArray;\n        } else {\n            $ipconfig = $_SERVER[\"WINDIR\"] . \"\\system32\\ipconfig.exe\";\n            if (is_file($ipconfig)) {\n                @exec($ipconfig . \" \/all\", $this-&gt;returnArray);\n            } else {\n                @exec($_SERVER[\"WINDIR\"] . \"\\system\\ipconfig.exe \/all\", $this-&gt;returnArray);\n            }\n            return $this-&gt;returnArray;\n        }\n    }\n\n    \/**\n     * \u83b7\u53d6ipconfig \/all \u6bcf\u884c\u53c2\u6570\u8f6c\u5316\u4e3a\u6570\u7ec4\n     * @return array\n     *\/\n    public function forLinux()\n    {\n        @exec(\"ifconfig -a\", $this-&gt;returnArray);\n        return $this-&gt;returnArray;\n    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/** * \u83b7\u53d6MacAddress * @var arra&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-727","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=727"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/727\/revisions"}],"predecessor-version":[{"id":1130,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/727\/revisions\/1130"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}