Suchen

Suche

Aktuell

  • Aktuell
  • Kommentare
  • TagCloud
  • Bis jetzt sind noch keine Kommentare geschrieben worden
 .Net   Suche   ASP.Net   Asp.Net   Beta   Buchtipp   C#   CentOS   CoD   DateTime   DiceFight   Funktion   HTML   HowTo   HttpWebRequest   IIS7   JSON   Konfiguration   LCD   Lighttpd   Linux   Media   Microsoft   Mobile   Mono   MySQL   Oracle   Outlook   PHP   PostgreSQL   Programme   Quake3   RC   RealURL   SMTPE   SVN   Server   Snippet   TYPO3   Timeout   Treiber   Tutorial   USB   Vista   WebClient   Windows   bauer-martin.com   bm_chart   ffmpeg   x64 

Randnotiz

W3C

Valid XHTML Valid CSS

Tutorials, PHP - 28.01.2007 13:12 - Alter: 3 yrs
- Keine Kommentare

Funtion: ping($ip)

Tags: PHP, Tutorial, Funktion, ping

Folgende Funktion führt einen Ping auf die angegebene IP-Adresse ($ip) aus und liefert die Ping-Zeit zurück. Sollte die IP nicht erreichbar sein, wird 0.0 zurückgegeben.

Hinweis: Damit diese Funktion funktioniert, muss shell_exec auf dem Server erlaubt sein

function ping($ip) {
  if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
      $command = shell_exec('ping -n 1 '.$ip);
    else
      $command = shell_exec('ping -c 1 '.$ip);
 
    if(eregi('100%', $command)) {
      return '0.0';
    } else {
      $start = strpos($command, 'time=') + 5;
      $ende = strpos($command, 'ms');
      $mstime = substr($command, $start, $ende-$start);
 
      return $mstime;
    }
  } else {
    return '0.0';
  }
}



Blink del.icio.us Digg Furl Google Simpy Spurl Technorati Yahoo

Kommentare

  • Bis jetzt sind noch keine Kommentare geschrieben worden

Kommentar schreiben

Ins Gästebuch eintragen
CAPTCHA Bild zum Spamschutz