Solved

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

Posted on 2013-05-25
4
3,878 Views
Last Modified: 2013-05-26
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
0
Comment
Question by:PierceWeb
  • 2
4 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
'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.
0
 
LVL 7

Accepted Solution

by:
multimac earned 500 total points
Comment Utility
Basically you want to run something easy like
<?
exec("/sbin/ifconfig | grep HWaddr", $output);
print_r( $output);
?>

Open in new window


gives you
Array
(
    [0] => eth0      Link encap:Ethernet  HWaddr ff:51:0a:0b:04:af
)

Now you can check if your $mac is a substring in the command output. You could also regexp or cut out the HWaddr.
0
 
LVL 2

Author Closing Comment

by:PierceWeb
Comment Utility
multimac,

Thanks... that will work nicely!

Much appreciated.

Thanks,

Tom
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php image upload 3 24
linux boot fsck problem 3 43
Creating a slider 12 32
Creating Image Thumbnails Using PHP 3 14
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now