Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
  1. #1
    Junior Member gazman's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    28
    Member #
    566
    Does anyone know of a way to get a clients MAC address, preferably using PHP, on a Win2k server?

    One way I thought of would be using the exec cmd to first ping the client, then using arp -a to get the MAC, but this is a little longwinded as I intend to use this on the company intranet with several hundred computers.

    Anyone have any better suggestions?
    ~GaZ~

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    I don't believe it's possible for privacy reasons (remember, each MAC ID corresponds to a unique NIC which usually means a unique computer...remember the whole serial number in Intel chips fiasco?). Your may, longwinded as it may be, might be the only way.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Junior Member gazman's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    28
    Member #
    566
    Yeah, you're right
    Well, if anyone is looking for an un-elegant solution, here's what I used (tested on an intranet of Win2k computers).

    $comp is the computer name of which you wish to find the MAC. The computer is pinged once to ensure it is in the IP-to-physical-address translation table used by ARP. $haystack is the translation table. $IP is the needle in the haystack.

    Note: I added the blank space before using the strpos function so that if the string for which i am searching is at position 0, it will instead be at position 1, as if it is at position 0 the result of the function could be interpreted as false (instead of position 0).

    Code:
    function getMAC($comp)
    {
         $IP = gethostbyname($comp);
         exec("ping -n 1 $comp");
         $haystack = shell_exec("arp -a");
         $haystack = " ".$haystack;
         if (strpos($haystack, $IP) == false)
         {
              return "Cannot Obtain MAC";
         }
         else 
        {
              $pos = strpos($haystack, $IP);
              $haystack = substr($haystack, $pos);
              $parts = explode("\n",$haystack);
    
              foreach ($parts as $part)
              {
                   $part = " ".$part;
                   if (strpos($part, $IP) == false) 
                   {
                        # Do nothing. IP is not here
                   }
                  else 
                  {
                        # IP is on this line
                        $subparts = explode("    ",$part);
                        foreach ($subparts as $sub)
                        {
                            if (substr($sub,0,2) == "00") # All MACs start with "00"?
                            {  
    #NOTE: This following part just breaks the MAC up to eliminate the "-"s
                                 $macparts = explode("-",$sub); 
                                 $computer["mac"] = "";
                                 foreach ($macparts as $macp) 
                                       $computer["mac"].=$macp;
                            }
                        }
                   }
              }
        return "Oops. Couldn't find the IP for ".$comp;
    }
    return "Cannot Obtain MAC";
    }
    I'll play around with this more at work next week to improve the code, and if anyone is interested I'll post my developments.

    Happy Easter!:classic:
    ~GaZ~

  5. #4
    #01
    #01 is offline
    Junior Member
    Join Date
    Apr 2003
    Posts
    3
    Member #
    1139
    How about on a Unix server? Cause this code would only work if your website is hosted on a windows server right?

    Is it possible to work on a Unix server? I don't know how to write PHP so I have no idea what makes it work on a Windows server and not a Unix one.

    BTW... where would I add this code?

  6. #5
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    The code he showed requires a Windows server (all of the execs run mostly Windows-only stuff).
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  7. #6
    #01
    #01 is offline
    Junior Member
    Join Date
    Apr 2003
    Posts
    3
    Member #
    1139
    Thanx for the help you have given me here and at vb.org filburt1

    Hopefully sombody can come up with a way to do this on a unix server as well.

    Cause I feel Unix is more secure for websites... but that is my opinion.

  8. #7
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    FWIW if anybody finds this out, it would be very useful...
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  9. #8
    Junior Member gazman's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    28
    Member #
    566
    I've never used UNIX, but i'm pretty sure there are commands for getting any information you need (ie mac addresses)...

    check out http://www.php.net/manual/sk/ref.exec.php for php exec cmd information.

    Update on that stupid function I wrote earlier in the thread... the following does the same thing, a lot quicker (stupid me).

    PHP Code:
    function getMAC$comp 
    {
        
    $output shell_exec("nbtstat -a $comp");
        
    $output explode("\n",$output);
        
    $mac_line explode ("="$outputsizeof($output)-]);
        
    $mac trim($mac_line[1]);
        return 
    $mac

    Note: it'll only work on an intranet, running on a Windows server
    ~GaZ~

  10. #9
    #01
    #01 is offline
    Junior Member
    Join Date
    Apr 2003
    Posts
    3
    Member #
    1139
    What file do I place this in? And where in the file?

  11. #10
    Junior Member
    Join Date
    Apr 2005
    Posts
    5
    Member #
    9768
    not having a windows server to test on is the $comp value the ip address? I'm trying to build a gpl license system http://forums.devshed.com/t247889/s.html

    i need to find other solutions to locking to certain hosts using low level exec calls but i want to make it cross os compatible. any advice you could offer forexec functions would be greatly apprciated


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

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

Search tags for this page

get client mac address using php
,
get client mac php
,
get remote ip ping & get remote mac address using php
,
mac address php
,
php exec getmac to get client mac address
,

php get client mac

,

php get client mac address

,
php get mac address of client
,
php get net mac disk
,

php get remote mac address

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:17 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com