To show Mac & Ip Address in Captive portal Page (tutorial)

  • // GEt ip address

    // Run arp request
    $arp=arp $ipaddress;
    // breaks arp & get mac from it
    $lines = explode(" ", $arp);
    $macaddr = $lines[3];

    // Display Mac & IP address
    echo $macaddr;

    echo $ipaddress;


  • Hello,

    What command can I use to show hostname?

    I saw
    $hostname = gethostbyaddr($ipaddress);
    mentioned somewhere, but it does not appear to work.

    pfSense 2.1 beta 1 amd64


  • @kmnair:

    What command can I use to show hostname?


  • I am afraid I should have made the question more specific.

    I was referring to the context of displaying hostname in PHP,

    khan had posted how to display ipaddress and macaddress using php script.

    I wanted hostname also to be displayed in the above process.

    Does arp explode give a hostname in the output? If so how to retrieve it?

    Thanks for your time.


  • LAYER 8 Netgate

    Did you try using the captive portal function instead of your own callout to arp?

    In /usr/local/captiveportal/index.php I see:

    $clientip = $_SERVER['REMOTE_ADDR'];
    $clientmac = arp_get_mac_by_ip($clientip);

    That function is in /etc/inc/  It does things like try to ping $clientip first to repopulate the arp table if necessary and check the result with is_macaddr().

Log in to reply