我想出瞭如何運行Arp掃描並在頁面上顯示結果。現在我需要將信息插入到Mysql數據庫中。我知道如何插入單個記錄,但是我正在努力如何將許多記錄放入數據庫。似乎無法把頭圍住它。這裏是我的代碼我有這方面的信息,我該如何進入我的數據庫?
<?php
$link = mysqli_connect("localhost", "user", "password", "mydb");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
error_reporting(E_ALL);
ini_set('display_errors', '1');
$output = shell_exec("sudo arp-scan --interface=eth0 --localnet --numeric -- quiet| grep -e 80:82:87");
foreach (explode("\n", $output) as $host)
{
list($ip, $mac) = array_pad(explode("\t", $host),2,null);
echo "$ip $mac<br>";
}
// attempt insert query execution
$sql = "INSERT INTO phones (ipadd, mac) VALUES ('$ip', '$mac')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
任何幫助是極大的讚賞
把你的SQL查詢放入你的foreach循環中。 – aynber