所以我開發最終將運行一個shell通過比較當前的IP(廣東話郵寄了幾個變量和字符串
//get_ip.php
<?php
$current_ip = file_get_contents('http://www.ipaddresscheck.comlu.com/ip.php');
?>
)
來檢測IP地址更改腳本(如果任何人有興趣,http://www.ipaddresscheck.comlu.com/ip.php將只返回您的機器/路由器的公共IP)
到最新的一個記錄在mysql中。現在,我甚至不能通過電子郵件發送虛假的舊IP和真正的當前IP。當我嘗試通過電子郵件發送新舊IP時,它只會工作,我將舊的ip變量放在當前位置或根本沒有。它應該說
The old IP adresss was --- ".$old_ip."
The new IP address is --- ".$current_ip."
但這是行不通的。唯一可行的就是
The old IP adresss was --- ".$old_ip."
The new IP address is --- ".$old_ip."
或
The old IP adresss was --- ".$old_ip."
The new IP address is ---
<?php
//Get IP
include 'get_ip.php';
//Connect to SQL
mysql_connect('localhost','root','root');
//Select database
mysql_select_db("ip_changes") or die(mysql_error());
//Get Date Info
$date = date("D M Y");
$time = date("H i s");
//Generate SQL query
$sql="INSERT INTO ip (date, time, current_ip)
VALUES ('$date', '$time', '$current_ip')";
//Execute SQL
mysql_query($sql);
//$sqlcurrent = mysql_query(SELECT current_ip FROM ip ORDER BY id DESC LIMIT 1);
echo $current_ip;
$new_ip = $current_ip;
//Send Mail
$old_ip = '192.168.0.1';
$to = "[email protected]";
$subject = "IP Address Change";
$message = "Hello! This is an automated message from the IPMS. An IP address chamge has been
detected.
//Right here, I can only send out $old_ip, and nothing else. The date and time at the bottom does work.
The old IP adresss was --- ".$old_ip."
The new IP address is --- ".$old_ip."
The IP address change was detected at ---". $date. ' , '. $time;
$message1 = 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
$from = "[email protected]://mar-remote-net.dns2.us";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo 'Old IP:'.$old_ip.
'New IP:'.$current_ip;
?>
有什麼建議?
你可以檢查你的代碼獲取IP工作正常,即在get_ip.php文件中 –
只是在將郵件發送給郵件之前對郵件進行回顯。前面提到的 –