Jump to content

wk_down

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by wk_down

  1. I believe I have figured it out. I don't have my entire file finished yet so I haven't tested it, but here goes:

      function operating_system() {  /* Code to determine client OS -- Throw to $client_os */    if ($client_os == "Windows") {        $output = system('ipconfig /all');        $mac_pos = strpos($output, 'Physical Address') + 36;        $client_mac = substr($output, $mac_pos, ($mac_pos + 17));         setcookie('mac', $client_mac);    }    else if ($client_os == "OS X") {        $output = system('ifconfig -a');        $mac_pos = strpos($output, 'ether') + 6;        $client_mac = substr($output, $mac_pos, ($mac_pos + 17));        setcookie('mac', $client_mac);    }    else if ($client_os == "Linux") {        $output = system('ifconfig -a');        $mac_pos = strpos($output, 'HWaddr') + 7;        $client_mac = substr($output, $mac_pos, ($mac_pos + 17));        setcookie('mac', $client_mac);      }    else { print "An error has occured."; }  }
    Basically, I would run some code to establish the OS of the client and pass that to $client_os. $output recieves the dump from the ipconfig/ifconfig command. $mac_pos determines the point right before the MAC address and then the substr() function throws it to $client_mac. Sounds good to me in theory. If anyone sees something I missed, please feel free to comment.
  2. I am working on a project for a friend where I need to pass a client's MAC address to a MySQL database. I am fairly new to PHP (I have read the W3 tutorial, some of the PHP.net manual and own O'Reilly's Learning PHP 5) and cannot find a solution. What I have so far is this:

    <?php/* Some code to establish connection to client */if ($user_os == "Windows")   $ip_out = system('ipconfig /all');  $mac = strspn($ip_out, '??:??:??:??:??:??');elseif ($user_os == "Linux") {  $ip_out = shell_exec()                                /* ... and so on *//* Code to pass $mac into MySQL database */?>
    Is there a better function to use than strspn()? Not sure if I can pass a variable and a wildcard mask in that function anyway. Like I said, not sure where I can go with this. Any help would be much appreciated!
×
×
  • Create New...