Php obtains the code of the primary domain in the MAC address and URL of the NIC.

Source: Internet
Author: User
Php obtains the code of the primary domain in the MAC address and URL of the NIC.

  1. // Obtain the MAC address of the NIC

  2. @ Exec ("ipconfig/all", $ array );
  3. For ($ Tmpa; $ Tmpa If (eregi ("Physical", $ array [$ Tmpa]) {
  4. $ Mac = explode (":", $ array [$ Tmpa]);
  5. Echo $ mac [1];
  6. }
  7. }

  8. // Obtain the url primary domain

  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. ?>

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.