Skip to content

Instantly share code, notes, and snippets.

@taiar
Last active May 29, 2021 14:35
Show Gist options
  • Select an option

  • Save taiar/4732398 to your computer and use it in GitHub Desktop.

Select an option

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;
@Dingham

Dingham commented Dec 27, 2018

Copy link
Copy Markdown

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

bijancot commented Jan 3, 2019

Copy link
Copy Markdown

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
Copy Markdown

Thanks

@taiar

taiar commented Aug 12, 2020

Copy link
Copy Markdown
Author

not working in Azure Web app PHP. any suggestions?

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

@taiar

taiar commented Aug 12, 2020

Copy link
Copy Markdown
Author

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