Skip to content

Instantly share code, notes, and snippets.

@taiar
Last active May 29, 2021 14:35
Show Gist options
  • Save taiar/4732398 to your computer and use it in GitHub Desktop.
Save taiar/4732398 to your computer and use it in GitHub Desktop.
Get MAC address from Windows host server in PHP
<?php
/*
* Getting MAC Address using PHP
* Md. Nazmul Basher
*/
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 (erase) the output buffer
$findme = "Physical";
$pmac = strpos($mycom, $findme); // Find the position of Physical text
$mac=substr($mycom,($pmac+36),17); // Get Physical Address
echo $mac;
@venkateshSrinikki
Copy link

venkateshSrinikki commented May 30, 2016

not working in Azure Web app PHP. any suggestions?

@rahuladream
Copy link

Working Fine...

@sshaik305
Copy link

sshaik305 commented Feb 5, 2018

Hi Taiar,

All the time, its returning the hosted server physical address but not the client it was initiated..
Do you have any idea on how to get the client physical address

@AleSal
Copy link

AleSal commented Feb 22, 2018

This works:
<?php $ip_address = $_SERVER['REMOTE_ADDR']; $mac = arp $ip_address | cut -d " " -f4; echo "<br />Seu Mac é: "; echo $mac; ?>

@Dingham
Copy link

Dingham commented Dec 27, 2018

I thought I would just pitch in on this for anyone else looking for a MAC address solution. It's only possible on LAN(Local) to get a clients MAC address and you have to be on the same subnet. This will not work over the WAN (Internet). MAC address are part of LAN and is not transmitted over WAN so server side technology will not help, there is a Javascript solution available if you want to go down that route... Hope this helps someone down the line.

@bijancot
Copy link

bijancot commented Jan 3, 2019

I thought I would just pitch in on this for anyone else looking for a MAC address solution. It's only possible on LAN(Local) to get a clients MAC address and you have to be on the same subnet. This will not work over the WAN (Internet). MAC address are part of LAN and is not transmitted over WAN so server side technology will not help, there is a Javascript solution available if you want to go down that route... Hope this helps someone down the line.

Agree, i found some solution if u want to get local ip address of your user, you can refer to this link https://stackoverflow.com/questions/20194722/can-you-get-a-users-local-lan-ip-address-via-javascript

@yehonatan56
Copy link

Thanks

@taiar
Copy link
Author

taiar commented Aug 12, 2020

not working in Azure Web app PHP. any suggestions?

This is meant to get the physical address on the host server.

@taiar
Copy link
Author

taiar commented Aug 12, 2020

Hi Taiar,

All the time, its returning the hosted server physical address but not the client it was initiated..
Do you have any idea on how to get the client physical address

This is meant to get the physical address on the host server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment