PHP Classes

How to implement PHP website testing tools using the package Network Tools: Perform diagnostics of access to Internet services

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-10-20 (17 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
network_tools 1.0MIT/X Consortium ...5.4Networking, PHP 5, Tools, Web services
Description 

Author

This package can perform diagnostics of access to Internet services.

It provides a class that can access multiple types of Internet services to check their responses and display the responses on a Web page.

Currently, it can:

- Retrieve several types of DNS records for a domain: MX, A, TXT, PTR, CNAME, SOA, SPF.

- Connect to a given server using different protocols: TCP, HTTP, HTTPS, SMTP

- Send requests to given servers using different protocols: ping, traceroute, HTTPS, SSH, FTP, SMTP, DNS, POP3, IMAPS, POP3S, RDP, Telnet, SMTP submission, HTTP, MySQL.

In more detail, the NetworkTools class is a comprehensive PHP library designed for network and DNS diagnostic operations. It provides a unified interface for various network tests and DNS queries, with intelligent fallback mechanisms for restricted server environments.

The core features of the class automatically detect available PHP functions and system capabilities, implementing smart fallback strategies when certain functions are disabled. It offers both "real" system commands (ping, traceroute) and simulated alternatives using TCP connections when exec() is not available.

The class DNS functions support all major DNS record types, including MX records for email server configuration, A records for IP address resolution, TXT records for text-based DNS information, PTR records for reverse DNS lookups, CNAME records for aliases, SOA records for domain authority information, and SPF records for email authentication.

The class network connectivity tests provide TCP port testing to check open ports, SMTP server connectivity tests, HTTP/HTTPS availability checks with response time measurements, ping simulation using either ICMP or TCP-based alternatives, and traceroute simulation with intelligent path analysis.

When system commands are not available, the class provides intelligent fallbacks using creative alternatives.

The simulated ping tests multiple common ports (80, 443, 22, 25, etc.) to find an open connection and measures response times. The simulated traceroute analyzes DNS patterns and uses TCP connectivity tests to approximate network routing paths.

The universal lookup() function automatically detects input type, IP addresses trigger PTR lookups, email addresses trigger MX lookups for the domain portion, and domain names trigger A record lookups.

All functions return structured arrays with success and error status, timing information, and detailed results. The class includes formatting functions for HTML output and a comprehensive self-test function that generates a complete system capability report.

This class is ideal for network monitoring tools, server health checks, email deliverability testing, DNS troubleshooting, and general network diagnostics in web applications where system command access may be limited.

Picture of Thomas Trautner
  Performance   Level  
Name: Thomas Trautner <contact>
Classes: 2 packages by
Country: Germany Germany
Age: 47
All time rank: Not yet ranked
Week rank: Not yet ranked
Innovation award
Innovation award
Nominee: 1x

Instructions

Usage examples - Complete function overview:

$tools = new NetworkTools();

System check

$tools->selftest(); // Shows HTML report and exits with die()`  

DNS Functions (require domain names)


$mxResult = $tools->mx('google.com');                    // MX records

$aResult = $tools->a('google.com');                      // A record (IP)

$txtResult = $tools->txt('google.com');                  // TXT records

$cnameResult = $tools->cname('www.google.com');          // CNAME record

$soaResult = $tools->soa('google.com');                  // SOA record

$spfResult = $tools->spf('google.com');                  // SPF records


Reverse DNS (requires IP address)


$ptrResult = $tools->ptr('8.8.8.8');                     // PTR record

Connection Tests (domain/IP + optional port)


$tcpResult = $tools->tcp('google.com', 80, 10);          // TCP port test

$smtpResult = $tools->smtp('smtp.gmail.com', 25, 10);    // SMTP test

$httpResult = $tools->http('https://google.com', 10);    // HTTP test

$httpsResult = $tools->https('google.com', 10);          // HTTPS test

Information Services (require domain)


$whoisResult = $tools->whois('google.com', 10);          // WHOIS lookup   

Network Tools (domain or IP) - with method indication


$pingResult = $tools->ping('8.8.8.8', 4);                // Ping (real or fake)

$traceResult = $tools->trace('google.com', 20);          // Traceroute (real or fake)

Manual fallback functions


$fakePingResult = $tools->fakeping('google.com', 4);     // Force TCP ping

$fakeTraceResult = $tools->faketrace('google.com', 15);  // Force TCP traceroute

Universal lookup (auto-detects input type)


$autoResult1 = $tools->lookup('192.168.1.1');            // Auto PTR

$autoResult2 = $tools->lookup('google.com');             // Auto A record

$autoResult3 = $tools->lookup('[email protected]');        // Auto MX

Print example results


print_r($mxResult);

print_r($pingResult);    // Contains ['method' => 'real_ping' or 'fake_ping']

print_r($traceResult);   // Contains ['method' => 'real_traceroute' or 'fake_traceroute']

print_r($httpResult);

Example

<?php
include "network_tools.php";
$tools = new NetworkTools();
$domain = "google.com";
$tcpResult = $tools->tcp($domain, 80, 10);
$tools->display($tcpResult,"TCP - ".$domain." Port 80");
echo
"<hr>";
$smtpResult = $tools->smtp('smtp.'.$domain, 25, 10);
$tools->display($smtpResult,"SMTP - ".$domain." Port 25");
echo
"<hr>";
$httpResult = $tools->http('http://'.$domain);
$tools->display($httpResult,"HTTP - ".$domain);
echo
"<hr>";
$httpsResult = $tools->https($domain);
$tools->display($httpsResult,"HTTPS - ".$domain);
echo
"<hr>";
$ptrResult = $tools->ptr("8.8.8.8");
$tools->display($ptrResult,"PTR - 8.8.8.8");
echo
"<hr>";
$pingResult = $tools->ping($domain, 4); // ---- NEEDS SOME TIME
$tools->display($pingResult,"PING (4x) - ".$domain);
echo
"<hr>";
$traceResult = $tools->trace($domain, 20); // ---- NEEDS SOME TIME
$tools->display($traceResult,"Traceroute - ".$domain);
echo
"<hr>";
$mxResult = $tools->mx($domain);
$tools->display($mxResult,"MX - ".$domain);
echo
"<hr>";
$aResult = $tools->a($domain);
$tools->display($aResult,"A - ".$domain);
echo
"<hr>";
$txtResult = $tools->txt($domain);
$tools->display($txtResult,"TXT - ".$domain);
echo
"<hr>";
$cnameResult = $tools->cname($domain);
$tools->display($cnameResult,"CNAME - ".$domain);
echo
"<hr>";
$soaResult = $tools->soa($domain);
$tools->display($soaResult,"SOA - ".$domain);
echo
"<hr>";
$spfResult = $tools->spf($domain);
$tools->display($spfResult,"SPF - ".$domain);


  Examples (ping & trace need some time)External page   SelftestExternal page  

Open in a separate window

Open in a separate window

  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file examples.php Example Function examples
Plain text file network_tools.php Class Class with examples
Accessible without login Plain text file selftest.php Example Selftest Example

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 0%
Total:0
This week:0