WebmasterLingo
Windows 2003, cPanel & DirectAdmin Unix Web Hosting

Go Back   WebmasterLingo > Programming Corner
User Name
Password

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old January 20th, 2006, 02:34 AM   #1
wk_down
Registered User
 
Join Date: Jul 2005
Location: Chicago
Posts: 6
wk_down is on a distinguished road
Send a message via ICQ to wk_down Send a message via AIM to wk_down Send a message via Yahoo to wk_down
Question MAC Address via PHP

I am working on a project that requires logging the client's unique MAC address into a MySQL database. I will be using PHP to populate MySQL so if there is a script or function that allows me to gather a client's MAC, I'd appreciate any help.
wk_down is offline   Reply With Quote
Old January 25th, 2006, 12:02 AM   #2
wk_down
Registered User
 
Join Date: Jul 2005
Location: Chicago
Posts: 6
wk_down is on a distinguished road
Send a message via ICQ to wk_down Send a message via AIM to wk_down Send a message via Yahoo to wk_down
PHP Functions

Ok, here is what I could gather so far: (Applying to Windows machines)

Quote:
<?php

/* Some code to establish connection to client */

$ipconfig = popen("ipconfig /all", "r");
$ipconfig_output = fflush($ipconfig);
$mac = strspn($ipconfig_output, '??:??:??:??:??:??');

/* Code to pass $mac into MySQL database */

?>


Is there a better function than strspn() to retrieve the MAC? I am using the ??:??:??:??:??:?? because I need ? wildcards in that format to find the MAC address string.

I am relatively new to PHP so please don't flame. I am truely trying to learn on my own but could not find much better in the php.net manual.
wk_down is offline   Reply With Quote
Old January 25th, 2006, 03:08 AM   #3
ZYV
PHP addict
 
Join Date: Dec 2003
Location: Russia, Nizhny Novgorod
Posts: 71
ZYV is off the scale
Send a message via ICQ to ZYV Send a message via AIM to ZYV
Hi!

I am not sure if I correctly understand what you need, but it seems to me that you are definitively going in the wrong direction. Do you need to log the MAC address of the site visitor to the DB or your NIC's address? You should always understand "ipconfig /all" gives you YOUR NIC's MAC, not the one of someone talking to you.

If you need the MAC by IP and you know that this IP belongs to someone currently talking to you it surely must be in the ARP cache of you box, so you need

1) Get the IP of the guy
2) Crawl the ARP cache by IP


Code:
zyv:# arp -a | grep "192.168.101.57" ? (192.168.101.57) at 00:05:5D:33:XX:FF [ether] PERM on br0


So basically you need something like this:

PHP Code:
<?php

$dirty 
= `arp -a | grep "192.168.101.57"`;
// Returns: "? (192.168.101.57) at 00:05:5D:33:C8:FF [ether] PERM on br0"
ereg ("([0-9A-Fa-f]{2}(:?)){6}"$dirty$reg);

$mac $reg[0];

// Now go ahead with your DB stuff

// ([0-9A-Fa-f]{2}(:?)){6} basically that matches the MAC, we could me more accurate  => secure, but I don't care, I trust ARP output.

?>


Hope that answers your questions.
__________________
God is real, unless declared as integer
ZYV is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -5. The time now is 02:41 AM.

JustEdge Dedicated Servers