Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Displaying MAC address on Captive Portal login page?

    Scheduled Pinned Locked Moved Captive Portal
    2 Posts 1 Posters 5.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      docwho76
      last edited by

      Is it possible to display the users MAC address on the CP login page? I have searched the forums and looked in the wiki and Googles a bunch and havent been able to find anything recent, or conclusive that helps.

      Is there documentation anywhere of the different variables that can be used, like for example the:

      Is there a REMOTE_MAC? What others are there? Thanks!

      1 Reply Last reply Reply Quote 0
      • D
        docwho76
        last edited by

        Ok, answering my own question here. This is the code I added to my PHP login page to make it work

        function returnmacAddress() {
        // This code is under the GNU Public Licence
        // Written by michael_stankiewicz {don't spam} at yahoo {no spam} dot com 
        // Get the arp executable path
        $location = `which arp`;
        $location = rtrim($location);
        
        // Execute the arp command and store the output in $arpTable
        $arpTable = `$location -a`;
        
        // Split the output so every line is an entry of the $arpSplitted array
        $arpSplitted = split("\n",$arpTable);
        
        // Get the remote ip address (the ip address of the client, the browser)
        $remoteIp = $GLOBALS['REMOTE_ADDR'];
        $remoteIp = str_replace(".", "\\.", $remoteIp);
        
        // Cycle the array to find the match with the remote ip address
        foreach ($arpSplitted as $value) {
        	// Split every arp line, this is done in case the format of the arp
        	// command output is a bit different than expected
        	$valueSplitted = split(" ",$value);
        	foreach ($valueSplitted as $spLine) {
        		if (preg_match("/$remoteIp/",$spLine)) {
        		$ipFound = true;
        		}
        		// The ip address has been found, now rescan all the string
        		// to get the mac address
        		if ($ipFound) {
        			// Rescan all the string, in case the mac address, in the string
        			// returned by arp, comes before the ip address
        			// (you know, Murphy's laws)
        			reset($valueSplitted);
        			foreach ($valueSplitted as $spLine) {
        				if (preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$spLine)) {
        					return $spLine;
        				}
        			}
        		}
        		$ipFound = false;
        	}
        }
        return false;
        }
        ?>
        

        And then where I want to display the MAC address we put:

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.