Assalam-o-Alaikum!
Friends today I am going to that ‘How to get MAC address and IP address of Windows”. Trick is very simple, you have to run ‘ipconfig/all’ command through ‘System’ programme and then you will capture output and save into variable with ‘ob_get_contents()’ function. It will return you an array and from this array you have to pull out your MAC address by search a word “Physical”. Now with “strpos()” and “substr()” function you will get your required MAC address.
Here is code:-
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php ob_start(); // Turn on output buffering system('ipconfig /all'); //Execute external program to display output $mycom=ob_get_contents(); // Capture the output into a variable ob_clean(); // Clean the output buffer $find_word = "Physical"; $pmac = strpos($mycom, $find_word); // Find the position of Physical text in array $mac=substr($mycom,($pmac+36),17); // Get Physical Address echo $mac; ?> |
Now lets move to our next step. You need IP address of your host. It is very simple function.
1 2 3 4 5 6 |
<?php $localIP = getHostByName(getHostName()); echo $localIP; ?> |
You can write functions for both tricks. You can use these functions anywhere as per your need. Here is function for MAC address:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php function get_mac(){ ob_start(); // Turn on output buffering system('ipconfig /all'); //Execute external program to display output $mycom=ob_get_contents(); // Capture the output into a variable ob_clean(); // Clean the output buffer $find_word = "Physical"; $pmac = strpos($mycom, $find_word); // Find the position of Physical text in array $mac=substr($mycom,($pmac+36),17); // Get Physical Address return $mac; } ?> |
and call this function like this
1 2 3 |
<?php echo get_mac(); ?> |
As you can see it is very simple. No need to explain.
Have a nice coding. Meet you in next tutorial.
how to get my system config in php
Please refer to this post
http://ice786pk.com/how-to-get-mac-and-ip-address-of-windows-system-with-php/