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

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

    Scheduled Pinned Locked Moved Captive Portal
    5 Posts 4 Posters 3.2k 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.
    • K
      khan
      last edited by

      // GEt ip address
      $ipaddress=$_SERVER['REMOTE_ADDR'];
      $macaddr=false;

      // 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;

      ?>

      1 Reply Last reply Reply Quote 0
      • K
        kmnair
        last edited by

        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

        Regards

        1 Reply Last reply Reply Quote 0
        • W
          wallabybob
          last edited by

          @kmnair:

          What command can I use to show hostname?

          hostname

          1 Reply Last reply Reply Quote 0
          • K
            kmnair
            last edited by

            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.

            kmnair

            1 Reply Last reply Reply Quote 0
            • DerelictD
              Derelict LAYER 8 Netgate
              last edited by

              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/util.inc.  It does things like try to ping $clientip first to repopulate the arp table if necessary and check the result with is_macaddr().

              Chattanooga, Tennessee, USA
              A comprehensive network diagram is worth 10,000 words and 15 conference calls.
              DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
              Do Not Chat For Help! NO_WAN_EGRESS(TM)

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