Visualizzazione dei risultati da 1 a 6 su 6

Discussione: ping

  1. #1

    ping

    Salve,
    sapete se possobile effettuare un ping su un indirizzo IP e porta??

    Però deve essere una cosa veloce, non che impiega tipo 5 sec..
    perchè dovrei mettere nel menu 5 server e devo controllare se sono online o offline, quindi se impiega x fare 1 ping di 5 sec x ogni server, alla fine è un può troppo....

    Spero che qualcuno mi può aiutare...

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    1,141
    prova:

    $out = shell_exec("ping xxx.xxx.xxx.xxx");
    echo "<pre>";
    print_r($out);
    echo "</pre>";


    ciao

  3. #3
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
    <head>
    <title>The WorldsEnd.NET - Free Ping Script, written in PHP</title>
    </head>
    <?php
    //  This script was writen by [email]webmaster@theworldsend.net[/email], Aug.2001
    //  [url]http://www.theworldsend.net[/url] 
    //  This is my first script. Enjoy.
    //  
    // Put it into whatever directory and call it. That's all.
    // Updated to 4.2 code 
    // Get Variable from form via register globals on/off
    //-------------------------
    $max_count 10//maximum count for ping command
    $unix      =  1//set this to 1 if you are on a *unix system      
    $windows   =  0//set this to 1 if you are on a windows system
    // -------------------------
    // nothing more to be done.
    // -------------------------
    //globals on or off ?
    $register_globals = (bool) ini_get('register_gobals');
    $system ini_get('system');
    $unix = (bool) $unix;
    $win  = (bool)  $windows;
    //
    If ($register_globals)
    {
       
    $ip getenv(REMOTE_ADDR);
       
    $self $PHP_SELF;

    else 
    {
       
    $submit $_GET['submit'];
       
    $count  $_GET['count'];
       
    $host   $_GET['host'];
       
    $ip     $_SERVER['REMOTE_ADDR'];
       
    $self   $_SERVER['PHP_SELF'];
    };
    // form submitted ?
    If ($submit == "Ping!"
    {
       
    // over count ?
       
    If ($count $max_count
       {
          echo 
    'Maximum for count is: '.$max_count;
          echo 
    '[url="'.$self.'"]Back[/url]';
       }
       else 
       {
          
    // replace bad chars
          
    $hostpreg_replace ("/[^A-Za-z0-9.]/","",$host);
          echo 
    '<body bgcolor="#FFFFFF" text="#000000"></body>';
          echo(
    "Ping Output:
    "
    ); 
          echo 
    '<pre>';           
          
    //check target IP or domain
          
    if ($unix
          {
             
    system ("ping -c$count -w$count $host");
             
    system("killall ping");// kill all ping processes in case there are some stalled ones or use echo 'ping' to execute ping without shell
          
    }
          else
          {
             
    system("ping -n $count $host");
          }
          echo 
    '</pre>';
        }

    else 
    {
        echo 
    '<body bgcolor="#FFFFFF" text="#000000"></body>';
        echo 
    '

    <font size="2">Your IP is: '
    .$ip.'</font></p>';
        echo 
    '<form methode="post" action="'.$self.'">';
        echo 
    '   Enter IP or Host <input type="text" name="host" value="'.$ip.'"></input>';
        echo 
    '   Enter Count <input type="text" name="count" size="2" value="4"></input>';
        echo 
    '   <input type="submit" name="submit" value="Ping!"></input>';
        echo 
    '</form>';
        echo 
    '
    [b]'
    .$system.'[/b]';
        echo 
    '</body></html>';
    }
    ?>
    preso da freephp

  4. #4
    quel codice fa un po schifo

    - non serve il system("killall ping");
    - non serve definire delle variabili per indicare il sistema operativo, piuttosto c'è la costante magica PHP_OS
    - usa il register global a off (non direttamente ma diciamo che fa qualcosa che è preferibile non fare)

    e qualche altra cosina
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  5. #5
    Originariamente inviato da daniele_dll
    quel codice fa un po schifo
    è il primo che mi è uscito da freephp con la ricerca ping

  6. #6
    grazie a tutti gli script che avete postato, il primo è bello piccolo, devo provare se funziona uso quello altrimenti provo il secondo, ho dato uno sguardo veloce e ha molte funzioni utili....

    Cmq li provo domani che adesso è troppo tardi, vado a dormire..


    Grazie ancora..

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.