Avatar of PierceWeb
PierceWeb
Flag for United States of America asked on

Get Mac address of Linux server via a PHP script running on server

Hello (PHP, Linux) Experts,

I'm hoping to be able to restrict access to a PHP program I wrote, to one specific Ubuntu server, based on its Mac address, (i.e., access the Mac address and compare it against the Mac address stored in an obfuscated file on the server).

The program will be hosted on a client's Ubuntu server. I'm trying to restrict the operation of the program to this one specific server Mac address.

Is there a means of programmatically accessing the Mac address of the Linux server via PHP script?

Note: I've seen a half dozen PHP scripts that DO NOT WORK... or only work on Windows servers. I need some PHP code that will work on an Ubuntu Linux server.

Is it even possible to access the Mac address of a Linux server from a PHP program... or is Linux too smart?

Thanks!

Tom
PHPLinuxWeb Servers

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Dave Baldwin

'ifconfig' where you would find the MAC address apparently requires elevated or root privileges.  You could 'sudo' your PHP program on the command line and get the information.  If you are running thru Apache, it would be more difficult to get the correct permissions.
ASKER CERTIFIED SOLUTION
multimac

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PierceWeb

ASKER
multimac,

Thanks... that will work nicely!

Much appreciated.

Thanks,

Tom
Dave Baldwin

Cool, I couldn't get a slightly different version to work yesterday but this one works on my Ubuntu system.  I suggest adding 'eth0' to the command or else on systems like mine where there are many IP addresses, you will get many lines of information.  And if they are simply additional IPs on the same interface, it just repeats the MAC address and other stuff over and over again.
<?
exec("/sbin/ifconfig eth0 | grep HWaddr", $output);
print_r( $output);
?>

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck