// Load the DHCP page HTML into a DOMDocument $dom = new DOMDocument(); @$dom->loadHTML($dhcp_response); libxml_clear_errors(); // Create a new DOMXPath instance $xpath = new DOMXPath($dom); // Initialize an array to store IP addresses $ip_addresses = []; // Find the table containing the DHCP Clients information $tables = $dom->getElementsByTagName('table'); foreach ($tables as $table) { // Check if the table has headers matching the DHCP Clients table $header_row = $table->getElementsByTagName('tr')->item(0); if ($header_row) { $headers = $header_row->getElementsByTagName('td'); if ($headers->length > 1 && trim($headers->item(1)->nodeValue) == 'IP Address') { // Iterate over each row in the table (skip header row) $rows = $table->getElementsByTagName('tr'); for ($i = 1; $i < $rows->length; $i++) { $cells = $rows->item($i)->getElementsByTagName('td'); if ($cells->length > 1) { // Extract the IP address from the second cell $ip = trim($cells->item(1)->nodeValue); $ip_addresses[] = $ip; } } break; // Exit loop after finding the desired table } } } // Output the extracted IP addresses foreach ($ip_addresses as $ip) { echo $ip . "\n"; }