wk_down Posted January 25, 2006 Share Posted January 25, 2006 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! Link to comment Share on other sites More sharing options...
wk_down Posted January 26, 2006 Author Share Posted January 26, 2006 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. Link to comment Share on other sites More sharing options...
_underscore_ Posted January 27, 2006 Share Posted January 27, 2006 um... you DO know you're not executing those commands on the client, but on the server? Link to comment Share on other sites More sharing options...
aspnetguy Posted January 27, 2006 Share Posted January 27, 2006 You'll have to use JavaScript or some other CLIENT script to get the values you want. Link to comment Share on other sites More sharing options...
_underscore_ Posted February 2, 2006 Share Posted February 2, 2006 For that matter, browsers won't usally tell you thier MAC Address. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now