www.webdeveloper.com
Results 1 to 5 of 5

Thread: Not Sure how to approach

  1. #1
    Join Date
    Aug 2006
    Posts
    112

    Not Sure how to approach

    Im working on a project that is a IP monitor system.
    I have created a database and the script works for the most part. Now i wanted to added a few functions to help us out.
    Basicly this script runs and pings all these ip's and tells me weither or not its up. That works fine but takes almost 7 minutes to load cause there are 1320 Ip's it needs to ping. What i would like for it to do is only display the sites that failed the ping.
    Here is the main script along with my ping script.
    Code:
    <html>
    <head>
    <title>IP Monitor</title>
    </head>
    <body>
    <meta http-equiv="refresh" content="600">
    
    <?php
    echo "<center>IP Monitor</center>";
    include ('functions.php');
    require_once('inc/conn.php');
    
    echo "<center><form action='{$_SERVER['PHP_SELF']}' method='POST'>\n".
         "  <table width='450' border='0' cellspacing='3' cellpadding='3' id='ipmon'>\n".
         "      <tr align=center valign=top>\n".
         "      <td align=center valign=top><b>Property</b></td>\n".
         "      <td align=center valign=top><b>IP</b></td>\n".
    	 "		<td align=center valign=top><b>Status</b></td>\n".
         "      </tr>\n";
    $result  = mysql_query("Select prop, ip from ipinfo");
    while ($row = mysql_fetch_array($result))
        {
    	echo "<tr align=center valign=top>\n".
             "<td align=center valign=top>". $row['prop']. "</td>\n".
             "<td align=center valign=top>". $row['ip']. "</td>\n".	
    	   	 "<td align=center valign=top>"; ping($row["ip"]); echo "</td>\n".
             "</tr>\n";
        }
    echo "</table>\n".
         "</form>".
    	 "</center>";
    ?>
    
    
    
    
    
    </body>
    </html>
    Ping Function
    Code:
    <?php
    function ping($ProxyServer){
    // false proxy used to generate connection error
           $ProxyPort = 80;
           $timeout= 5;
    // must use next two statements
           set_time_limit(0);  //Time for script to run .. not sure how it works with 0 but you need it
           ignore_user_abort(true); //this will force the script running at the end
    // Create Proxy      
           $handle = fsockopen($ProxyServer,$ProxyPort,$errno,$errstr,$timeout);    
           if (!$handle){
               echo "<img src='images/red.jpg'><br>";
    	   } else {
    // copied method for PING like time operation
               $status = socket_get_status($handle);
               stream_set_timeout($handle);     
    //send somthing
               $write = fwrite($handle,"echo this\n");
               if(!$write){
                   return 0;
               }
               stream_set_blocking($handle,0); 
    //Try to read. the server will most likely respond with a "ICMP Destination Unreachable" and end the read. But that is a responce!
               fread($handle,1024);
               fclose($handle);
               echo "<img src='images/green.jpg'><br>";
    	   }
    }
    
    ?>
    Any help that could point me into the right direction is a big help and much appricated. Thanks!!!

  2. #2
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    PHP Code:
    <html>
    <head>
    <title>IP Monitor</title>
    </head>
    <body>
    <meta http-equiv="refresh" content="600">

    <center>IP Monitor</center>

    <center>
        <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='POST'>
        <table width='450' border='0' cellspacing='3' cellpadding='3' id='ipmon'>
        <tr align="center" valign="top">
            <td align="center" valign="top"><b>Property</b></td>
            <td align="center" valign="top"><b>IP</b></td>
            <td align="center" valign="top"><b>Status</b></td>
        </tr>
        
    <?php
    include ('functions.php');
    require_once(
    'inc/conn.php');

    $result mysql_query("Select prop, ip from ipinfo");
    while(
    $row mysql_fetch_array($result))
    {
    ?>
        <tr align="center" valign="top">
            <td align="center" valign="top"><?php echo $row['prop']; ?></td>
            <td align="center" valign="top"><?php echo $row['ip']; ?></td>
            <td align="center" valign="top"><img src="images/<?php echo (ping($row['ip'])) ? "green" "red"?>"><br></td>
        </tr>
    <?php
    }
    ?>
        </table>
        </form>
    </center>

    </body>
    </html>

    PHP Code:
    <?php
    function ping($ProxyServer)
    {
        
    $ProxyPort        80;
        
    $timeout        5;
        
        
    set_time_limit(0);
        
    ignore_user_abort(true);
        
        
    // Create Proxy      
        
    $handle fsockopen($ProxyServer$ProxyPort$errno$errstr$timeout);    
        if(!
    $handle)
        {
            return 
    false;
        } else {
            
    $status socket_get_status($handle);
            
    stream_set_timeout($handle);   
              
            
    //send somthing
            
    $write fwrite($handle,"echo this\n");
            
            if(!
    $write)
                return 
    false;
            
            
    stream_set_blocking($handle,0); 
            
            
    fread($handle,1024);
            
    fclose($handle);
            
            return 
    true;
        }
    }
    ?>

  3. #3
    Join Date
    Aug 2006
    Posts
    112
    Well Unfortantly that didnt work. Still posted all 1320 sites along with now showing a red X cause it cant find the image.
    I think i have to just rewrite the whole thing. Have it hide the array and only display the ones that fail.
    I'll try to muster something up
    Thanks again for the help

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    What is the major issue? The 1320 hosts in the list or the 7 minutes it takes to ping all of them?

    If you just want to suppress the successful pings, you'll have to change this:
    PHP Code:
    while($row = mysql_fetch_array($result))
    {
    ?>
        <tr align="center" valign="top">
            <td align="center" valign="top"><?php echo $row['prop']; ?></td>
            <td align="center" valign="top"><?php echo $row['ip']; ?></td>
            <td align="center" valign="top"><img src="images/<?php echo (ping($row['ip'])) ? "green" "red"?>"><br></td>
        </tr>
    <?php
    }
    to this:
    PHP Code:
    <?php
    while($row mysql_fetch_array($result)) {
      if (!
    ping($row['ip'])) {
        
    ?>
        <tr align="center" valign="top">
          <td align="center" valign="top"><?php echo $row['prop']; ?></td>
          <td align="center" valign="top"><?php echo $row['ip']; ?></td>
          <td align="center" valign="top"><img src="images/red.jpg"><br></td>
        </tr>
        <?php
      
    }
    }
    ?>
    This will cut the list down but it won't save any time.

  5. #5
    Join Date
    Aug 2006
    Posts
    112
    thats exactly what i wanted to do!! suppress the successful pings. Thanks alot!!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles