


So pingen Sie einen Server-Port mit PHP an: Eine Schritt-für-Schritt-Anleitung
Pinging a Server Port with PHP
As you've correctly noted, the provided PHP script is designed to ping websites by their domain name. To adapt it for pinging specific IP addresses and port numbers, we need to make some adjustments.
The key function you'll need is fsockopen(), which allows you to establish a socket connection to a remote server. By specifying the server's IP address and port number, you can attempt to connect and verify if the server is accepting connections on that specific port.
Here's a revised version of the ping function:
<code class="php">function pingPort($ip, $port, $timeout) { $tB = microtime(true); $fP = fsockopen($ip, $port, $errno, $errstr, $timeout); if (!$fP) { return "down"; } $tA = microtime(true); return round((($tA - $tB) * 1000), 0)." ms"; }</code>
This function takes three arguments:
- $ip: The IP address of the server you want to ping
- $port: The port number you want to ping
- $timeout: The amount of time (in seconds) to wait for a response before giving up
If the connection can be established, the function will return the round-trip time in milliseconds. Otherwise, it will return "down" to indicate that the port is not reachable.
To use the function, you can simply call it like this:
<code class="php">$ip = "192.168.1.100"; $port = 80; $timeout = 10; $ping = pingPort($ip, $port, $timeout); if ($ping == "down") { echo "Port $port is not reachable on $ip."; } else { echo "Ping to $ip:$port: $ping ms"; }</code>
This script will display the ping time if the port is reachable, or it will output an error message if the connection attempt fails.
Das obige ist der detaillierte Inhalt vonSo pingen Sie einen Server-Port mit PHP an: Eine Schritt-für-Schritt-Anleitung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

11 beste PHP -URL -Shortener -Skripte (kostenlos und Premium)

Arbeiten mit Flash -Sitzungsdaten in Laravel

Erstellen Sie eine React -App mit einem Laravel -Back -Ende: Teil 2, reagieren

Vereinfachte HTTP -Reaktion verspottet in Laravel -Tests

Curl in PHP: So verwenden Sie die PHP -Curl -Erweiterung in REST -APIs

12 Beste PHP -Chat -Skripte auf Codecanyon

Ankündigung von 2025 PHP Situation Survey
