欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php获取网卡MAC地址与URL中主域的代码

程序员文章站 2022-06-08 09:22:34
...
  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. ?>
复制代码