Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:34:14+00:00 2026-06-07T04:34:14+00:00

I would like to have a quick script listing all active hosts in a

  • 0

I would like to have a quick script listing all active hosts in a LAN, and I am a bit lost. From other posts I figured that this can be done most effectively by polling the DHCP server (in my case a Lancom router) using SNMP.

However, I am not familiar with the SNMP commands in PHP. Is snmpwalk() the correct function? Can I get snmpwalk() or any other php function to return an array that contains a list of all live hosts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:34:16+00:00Added an answer on June 7, 2026 at 4:34 am

    So I wrote a script that probes the Lancom router and pulls out the DHCP/BOOTP table. It may be used for all those who need to monitor such routers, and therefore I am sharing it. It also outputs a nice HTML table; the function BetterTable() can be used on any 2D array.

    You will need to set IP, userid, and pwd (first three variables) in order to use the script on your router.

        <?php
    
        $router_ip = '';
        $username = '';
        $password = '';
        $port = 23;
        $timeout = 10;
    
        $connection = fsockopen($router_ip, $port, $errno, $errstr, $timeout);
    
        if(!$connection){
         echo "Connection failed\n";
         exit();
        } else {
    
         fputs($connection, "$username\r\n");
         fputs($connection, "$password\r\n");
         fputs($connection, "cd setup/dhcp/dhcp-table \r\n");
         fputs($connection, "dir \r\n");
         fputs($connection, " ");
    
         $j = 0;
         while ($j < 16) {
          fgets($connection);
          $j++;
         }
         stream_set_timeout($connection, 2);
         $timeoutCount = 0;
         $content ='';
         $DhcpArray = '';
         (int) $index =0;
    
        $DhcpFile = "C:\IP-Symcon\webfront\user\images\LancomDhcp.txt";
        $fh = fopen($DhcpFile, 'w') or die("can't open file");
    
        //$DhcpArray[0] = array ('IP-Address', 'MAC-Address', 'Timeout', 'Hostname', 'Type', 'LAN-Ifc', 'Ethernet-Port', 'VLAN-ID', 'Network-Name');
    
         while (!feof($connection)){
    
          $content = fgets($connection);
          $content = str_replace("\r", '', $content);
          $content = str_replace("\n", "", $content);
          $lineArray = explode(' ', $content); 
          if (isValidIp($lineArray [0]))
              { 
              $DhcpArray[$index]['IP-Address'] = substr ($content, 0,17);
              $DhcpArray[$index]['MAC-Address'] = substr ($content, 17,32-18);
              $DhcpArray[$index]['Timeout'] = substr ($content, 31,41-32);
              $DhcpArray[$index]['Hostname'] = substr ($content, 40,108-41);
              $DhcpArray[$index]['Type'] = substr ($content, 107,125-108);
              $DhcpArray[$index]['LAN-Ifc'] = substr ($content, 124,137-125);
              $DhcpArray[$index]['Ethernet-Port'] = substr ($content, 136,152-137);
              $DhcpArray[$index]['VLAN-ID'] = substr ($content, 151,161-152);
              $DhcpArray[$index]['Network-Name'] = substr ($content, 160);
              fwrite($fh, $content);
              $index +=1;
              }
    
          # If the router say "press space for more", send space char:
          if (preg_match('/MORE/', $content) ){ // IF current line contain --More-- expression,
           fputs ($connection, " "); // sending space char for next part of output.
          } # The "more" controlling part complated.
    
          $info = stream_get_meta_data($connection);
          if ($info['timed_out']) { // If timeout of connection info has got a value, the router not returning a output.
           $timeoutCount++; // We want to count, how many times repeating.
          }
          if ($timeoutCount >2){ // If repeating more than 2 times,
           break;   // the connection terminating..
          }
         }
         $content = substr($content,410);
    
         BetterTable($DhcpArray);
    
    
    
    
        fclose($fh);
    
        }
        echo "End.\r\n";
    
        //--------------------------------------------------------------------
    
        function isValidIp($ip)
        {/* PCRE Pattern written by Junaid Atari */
            return !preg_match ( '/^([1-9]\d|1\d{0,2}|2[0-5]{2})\.('.
                                 '(0|1?\d{0,2}|2[0-5]{2})\.){2}(0|1?'.
                                 '\d{0,2}|2[0-5]{2})(\:\d{2,4})?$/',
                                 (string) $ip )
                    ? false
                    : true;
        }
    
        //--------------------------------------------------------------
    
        function BetterTable($twoDimArray)
        {
        $i = 0;
        echo "<table>
                <table class='BetterTable' border='1'>";
    
        echo "<tr>";
        echo '<td>Line #
        </td>';
        foreach ($twoDimArray[0] as  $fieldName => $fieldValue)
            {
                echo '<td>'.$fieldName. '</td>';
            }echo '</tr>';
        $i = 0;
    
        foreach ($twoDimArray as $rowName => $rowValue) 
        {
                if ($i%2 == 0) 
                    Echo "<tr bgcolor=\"#d0d0d0\" >";
                else 
                    Echo "<tr bgcolor=\"#eeeeee\">";
            $fields = count($twoDimArray[$i]);
            $y = 0;
            echo '<td>'.$i. '</td>';
            foreach ($rowValue as  $fieldName => $fieldValue)
            {
                echo '<td>'.$fieldValue. '</td>';
                $y = $y + 1;
            }
            echo '</tr>';
            $i = $i + 1;
        }
    
    
        echo '</table>';
        }
    
    
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to generate a dynamic image from a script, and then have
I would like to have a makefile copy files from another directory and change
In a quick-and-dirty Perl script, I have a data structure like this: $tax_revenue{YEAR}{STATE}{GOVLEV}{TAX} =
I would like to send mail from a script on a Windows Server 2003
I have a quick one off task in a python script that I'd like
So in my project i would like have a nice treeview that has images.
I would like to have an AppWidget that designed like this one . Image:
I would like to have a more colorful Python prompt in the terminal, just
I would like to have the cursor in the JavaDoc area when creating interfaces,
I would like to have a field which is updated on every change(insertion, modification),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.