+ Reply to Thread
Results 1 to 9 of 9

Thread: MAC Address via PHP

  1. #1
    Registered User wk_down is on a distinguished road
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    6

    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.

  2. #2
    Registered User wk_down is on a distinguished road
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    6

    PHP Functions

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

    <?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.

  3. #3
    Registered User dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    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.
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  4. #4
    Registered User RobJones1980 is on a distinguished road
    Join Date
    Feb 2008
    Location
    Crawley
    Posts
    5
    It's not practically possible to grab a MAC address by an IP address unless you do some client side edits, which defeats the point.

  5. #5
    Newbie smithlanger is on a distinguished road
    Join Date
    Apr 2010
    Posts
    1
    sounds good to me

  6. #6
    Registered User josaphlewis is on a distinguished road
    Join Date
    Jul 2010
    Posts
    8
    [font='Calibri','sans-serif']Hi friends, Thanks’ for your valuable post. I really forgot use of output buffering in PHP. I try to Your MAC address using JavaScript but it give me error i.e. automated server cannot create object.[/font]

  7. #7
    Newbie ethunhant is on a distinguished road
    Join Date
    Mar 2011
    Posts
    2
    I am doing programming for many years and PHP is my favorite programming language. Also, PHP has become the most popular Web programming language not only because it is free but it has many advantages in programming with PHP. Owing to the numerous benefits offered by PHP scripting language, it has gained a lot of popularity.

  8. #8
    Newbie tanyue123 is on a distinguished road
    Join Date
    May 2011
    Posts
    2

    HID Kit

    Do you have troubles about how to choose HID Kit? there are so many brands, and you can not distinguish which is the best HID Kit you need, here, i would like to recommend this VVME HID Kit, which is cheap, reliable, and almost identical to the factory HID on the tractors and they are not blue like other kits. for more info, please visit http://www.vvme.com.
    You may also interested in:
    Bi-Xenon HID Kit
    HID Conversion Kit
    Hi/Low HID Kit

  9. #9
    Newbie ghostfire58 is on a distinguished road
    Join Date
    Nov 2011
    Posts
    3
    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

    _________________

    One evening I drove my husband's car to the shopping mall.in Diablo 3 Accounts
    On my return, I noticed that how dusty the outside of his car was and cleaned it up a bit.When I finally entered the house, I called out."The woman who loves you the most in the world Diablo 3 Items just cleaned your headlights and windshield."
    My husband looked up and said, "Mom's here?"
    Diablo 3 Gold

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts