Home  >  Article  >  Backend Development  >  PHP gets the MAC address of the network card and the code of the main domain in the URL

PHP gets the MAC address of the network card and the code of the main domain in the URL

WBOY
WBOYOriginal
2016-07-25 09:00:34815browse
  1. //获取网卡MAC地址

  2. @exec("ipconfig/all",$array);
  3. for($Tmpa;$Tmpaif(eregi("Physical",$array[$Tmpa])){
  4. $mac=explode(":",$array[$Tmpa]);
  5. echo $mac[1];
  6. }
  7. }

  8. //获取url主域

  9. //by http://bbs.it-home.org
  10. function GetDomain($url){
  11. $pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";
  12. preg_match($pattern, $url, $matches);
  13. if(count($matches) > 0){
  14. return $matches[0];
  15. }else{
  16. $rs = parse_url($url);
  17. $main_url = $rs["host"];
  18. if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {
  19. return $main_url;
  20. }else{
  21. $arr = explode(".",$main_url);
  22. $count=count($arr);
  23. $endArr = array("com","net","org","3322");//com.cn net.cn 等情况
  24. if(in_array($arr[$count-2],$endArr)){
  25. $domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];
  26. }else{
  27. $domain = $arr[$count-2].".".$arr[$count-1];
  28. }
  29. return $domain;
  30. }//end if(strcmp)
  31. }//end if(count)
  32. }//end fun
  33. ?>

复制代码


Statement:
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