我有大量的IP地址需要訪問以查看它們是否處於活動狀態。所以我的計劃是反覆重定向瀏覽器,然後使用後退按鈕查看每個頁面。做這個的最好方式是什麼?使用PHP或Javascript自動將瀏覽器重定向到許多IP地址
我很可能有一個IP地址陣列。像:
array(234.324, 2343.323432, 234.234, 234.4543)
那麼我可以用通過某種腳本語言循環和瀏覽器重定向到這些。期待看到一些很酷的解決方案。
我有大量的IP地址需要訪問以查看它們是否處於活動狀態。所以我的計劃是反覆重定向瀏覽器,然後使用後退按鈕查看每個頁面。做這個的最好方式是什麼?使用PHP或Javascript自動將瀏覽器重定向到許多IP地址
我很可能有一個IP地址陣列。像:
array(234.324, 2343.323432, 234.234, 234.4543)
那麼我可以用通過某種腳本語言循環和瀏覽器重定向到這些。期待看到一些很酷的解決方案。
繼Kovshenin的答覆,這裏是一個工具,我最近提出,將能夠幫助你。
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#error_toggle').click(function() {
$('#error_details').slideToggle('slow', function() {
});
});
$('#success_toggle').click(function() {
$('#success_details').slideToggle('slow', function() {
});
});
});
</script>
<style>
div
{
font-family: arial;
font-size: 12px;
}
#message
{
font-weight: bold;
font-size: 16px;
}
#error_toggle
{
width: 250px;
font-weight: bold;
text-align: center;
line-height: 25px;
background: #23ae66;
color: #ffffff;
height: 25px;
cursor: pointer;
}
#error_details
{
display: none;
background: #2b2b2b;
padding: 5px;
color: #ffffff;
width: 240px;
}
#success_toggle
{
width: 350px;
font-weight: bold;
text-align: center;
line-height: 25px;
background: #23ae66;
color: #ffffff;
height: 25px;
cursor: pointer;
}
#success_details
{
width: 340px;
display: none;
padding: 5px;
color: #ffffff;
background: #2b2b2b;
}
</style>
</head>
<body>
<?php
//Setting up the correct URL and stripping it of un-needed content
$url = $_GET['url'];
$unwanted_args = array('http://', 'www.');
$clean_url = str_replace($unwanted_args, '', $url);
$clean_url = trim($clean_url);
//Initalizing CURL
$set_curl = curl_init($url);
// Setting the array for which headers to return.
$headers = array('Expect:');
//Setting required CURL options
curl_setopt($set_curl, CURLOPT_FAILONERROR, true);
curl_setopt($set_curl, CURLINFO_HEADER_OUT, true);
curl_setopt($set_curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($set_curl, CURLOPT_TIMEOUT, 1);
curl_setopt($set_curl, CURLOPT_HEADER, false);
curl_setopt($set_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($set_curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
//Execute request
curl_exec($set_curl);
//Check to see if the website is down
if(curl_error($set_curl)) {
echo '<div id="message">' . $clean_url . ' is down</div>';
echo '<div id="error_toggle">Details</div>';
echo '<div id="error_details">';
echo curl_error($set_curl) . '<br />';
echo 'Error number: ' . curl_errno($set_curl) . '<br />';
echo '</div>';
}
//Else display success message
else {
$info = curl_getinfo($set_curl);
echo '<div id="message">Success! <a href="' . $info['url'] . '">' . $clean_url . '</a> is currently online</div>';
echo '<div id="success_toggle">Details</div>';
echo '<div id="success_details">';
echo 'Url: ' . $info['url'] . '<br />';
echo 'Total Time: ' . $info['total_time'] . ' Seconds<br />';
echo 'Average download speed: ' . $info['speed_download'] . ' bytes<br />';
echo 'Content Type: ' . $info['content_type'] . '<br />';
echo 'Queried with: ' . $info['request_header'] . '<br />';
echo '</div>';
}
//Close CURL conncetion.
curl_close($set_curl);
?>
</body>
</html>
使用cURL
那些不喜歡看的IP地址給我,但不管。你爲什麼不讓自己的代碼抓取你感興趣檢查的每一頁?
我很確定他輸入隨機數字作爲示例,而不是實際數據。 – ceejayoz 2010-10-25 16:37:58
這不推薦。
如果你有一個支持PHP的服務器,可以ping每個域:
<?php
function pingDomain($domain){
$starttime = microtime(true);
$file = fsockopen ($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
?>
這個工具很棒,只需要添加一個循環,也許還有其他一些mods,並且應該全部設置。非常感謝。 – Mike 2010-10-25 17:22:23
謝謝,意味着很多!一些注意事項,對於HTTPS,您可能會遇到一些錯誤,如果返回代碼超過400(主要是404和500)並且超時設置爲1秒,它將返回網站。只需要考慮一些事情。 – 2010-10-25 17:47:53