1

ネットワーク上の静的 IP のリストを把握するために使用する、作成したデータベースがあります。IPを順番にリストするページがあり、IPとデータベースからの他のデータをリストするスクリプトは機能しますが、各IPアドレスにpingを実行して、それが稼働しているかどうかを確認するスクリプトを追加したいのですが、ここにコードがありますすべてを表示する必要があります:

$dbConn = connectToDb();

$sql= <<< END

SELECT *
FROM `ipadds` 
ORDER BY oct1 ASC, oct2 ASC, oct3 ASC, oct4 ASC;

END;

$result=mysql_query($sql) or die(mysql_error()); 



$options=""; 



while ($row=mysql_fetch_array($result)) {

    $oct1=$row['oct1']; 
    $oct2=$row['oct2']; 
    $oct3=$row['oct3']; 
    $oct4=$row['oct4']; 
    $SubnetMask=$row['SubnetMask']; 
    $Hostname=$row['Hostname']; 
    $MAC=$row['MAC']; 
    $Description=$row['Description']; 
    $DeviceType=$row['DeviceType']; 
    $Location=$row['Location']; 
    $Comments=$row['Comments']; 

    $options.="<tr><td><a href=editcomputer.php?queryID=$id><img src=images/edit.gif alt=print border=0></a> <a href=deletecomputer.php?queryID=$id><img src=images/edit-delete-icon.png alt=print border=0></a></td><td><a href='HTTP://$oct1.$oct2.$oct3.$oct4' target=_blank>$oct1.$oct2.$oct3.$oct4</a></td><td>$SubnetMask</td><td>$Hostname</td><td>$MAC</td><td>$Description</td><td>$DeviceType</td><td>$Location</td></tr>";

}
?> 
<center>

<font size=-1>

<img src="images/edit.gif"> - Edit Computer<br>

<img src="images/edit-delete-icon.png"> - Delete Computer<br>

</font>

<font size="2">

<table>

<tr>

<td>

<hr>

</td>

</tr>
<table cellpadding="15" border="1">
<tr>
<td>

</td>
<td>
<u>IP Address</u>
</td>
<td>
<u>Subnet Mask</u>
</td>
<td>
<u>Hostname</u>
</td>
<td>
<u>MAC Address</u>
</td>
<td>
<u>Description</u>
</td>
<td>
<u>Device Type</u>
</td>
<td>
<u>Location</u>
</td>

<?=$options?>
</table>

テーブルに別の行を追加して、それをアップまたはダウンの「ステータス」として表示したいのですが、何か提案はありますか?

このコードを見つけました。それはすべて単独で機能し、アドレスを指定しましたが、「while」ステートメントで機能させることができません:

function pingAddress($ip) {
    $pingresult = exec("ping -n 3 $ip", $outcome, $status);
    if (0 == $status) {
        $status = "alive";
    } else {
        $status = "dead";
    }
    echo "The IP address, $ip, is  ".$status;
}

pingAddress("ip addres of host here");
4

1 に答える 1

1

関数を使用してはならないことは言うmysql_*までもありません (おっと、私はちょうど使用しました)。値を返すように関数を変更するだけです。

function pingAddress($ip) {
    $pingresult = exec("ping -n 3 $ip", $outcome, $status);
    if (0 == $status) {
        return true;
    } 
    return false;
} 

あなたのループで:

while ($row=mysql_fetch_array($result)) {
    [...]
    if (pingAddress($ip) === true) {
        // IP is up
    }
    else {
        // IP is down
    }
}
于 2012-09-07T03:43:15.147 に答える