Advertisement
Guest User

retrieve MAC address

a guest
Dec 7th, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2. function getMac(){
  3. exec("ipconfig /all", $output);
  4. foreach($output as $line){
  5.         if (preg_match("/(.*)Physical(.*)/", $line)){
  6.                 $mac = $line;
  7.                 $mac = str_replace("Physical address. . . . . . . . . :","",$mac);
  8.                 $mac = trim($mac);
  9.                 echo $mac . "</br>";
  10.         }
  11. }
  12. return $mac;
  13. }
  14.  
  15. $mac = getMac();
  16. $mac = trim($mac);
  17. echo $mac;
  18. ?>
  19.  
  20.  
  21.  
  22.  
  23. <?php ob_start(); // Turn on output buffering
  24. system("ipconfig /all"); //Execute external program to display output
  25. $mycom=ob_get_contents(); // Capture the output into a variable
  26. ob_clean(); // Clean (erase) the output buffer
  27.  
  28. $findme = "Physical";
  29. $pmac = strpos($mycom, $findme); // Find the position of Physical text
  30. $mac=substr($mycom,($pmac+36),17); // Get Physical Address
  31.  
  32. echo $mac;
  33. ?>
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement