需要將所有 Tor 用戶從我的頁面轉發出去,并在 Tor 串列中檢查 ip。單項檢查適用于 ipv4,但不適用于 ipv6 和多串列檢查。無法理解我在哪里出錯。代碼:
$torip = file("https://check.torproject.org/torbulkexitlist", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$torexits = file("https://lists.fissionrelays.net/tor/exits-ipv6.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$tornode = file("https://lists.fissionrelays.net/tor/relays-ipv6.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$client_ip = $_SERVER['REMOTE_ADDR'];
if (in_array($client_ip, $torip)){
header('Location: https://www.google.com/');
}
if (in_array($client_ip, $tornode)){
header('Location: https://www.google.com/');
}
if (in_array($client_ip, $torexits)){
header('Location: https://www.google.com/');
}
正在嘗試不同的方式就像
if(in_array($client_ip, $torip) or in_array($client_ip, $tornode) or in_array($client_ip, $torexits))
如果... elseif .. elseif
同樣可以通過 tor 進入,ip 在串列中,無法理解問題出在哪里。感謝大家的幫助。
UDP:代碼部分
$tornode = file("https://lists.fissionrelays.net/tor/relays-ipv6.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$client_ip = $_SERVER['REMOTE_ADDR'];
if (in_array($client_ip, $tornode)){
header('Location: https://www.google.com/');
die();
}
正在 100% 作業 - 問題 - 如何以正確的方式在檢查中添加其他串列?
uj5u.com熱心網友回復:
這里有幾件事......
我希望您不要在每次有人訪問您的頁面時都下載這些串列。您應該將串列下載的結果快取一小段時間,而不是不斷下載。
您需要的唯一裂變繼電器串列是
exits.txt. 如https://fissionrelays.net/lists 所述,exits.txt 包含 IPv4 和 IPv6 出口節點。下載它而不是exits-ipv6.txt 和relays-ipv6.txt。阻止非出口的 Tor 中繼是不正確的。來自中繼 IP 的點擊不是Tor 流量。例如,我在家里運行了一個不允許出口流量的守衛中繼。它的 IP 出現在中繼串列中,但它不允許任何 Tor 退出流量,因此來自該 IP 的任何點擊都不是來自 Tor。
如果你想使用多個串列,那很好。我建議以下步驟來滿足您的需求:
1. Download & combine all lists every 10 minutes
2. De-duplicate and sort the list
3. Save to a file
4. Write a function to search the cached file.
對于 1-3,您可以使用https://gitlab.com/fissionrelays/lists/-/blob/master/tor.php這是裂變中繼提供的下載器來下載其串列。它也排序。
如果您的串列排序正確,您可以對串列進行二分搜索以獲得更好的結果,但這是更高級的并且不是必需的。
提示,下載串列時,不要使用file()以陣列形式下載。file_get_contents()改為使用,并將每個串列附加到另一個串列上。下載并組合所有串列后,將它們處理成一個陣列(跳過重復項),然后對串列進行排序。
這是一個二分搜索功能,您可以使用它來更快地搜索排序串列。
/**
* Perform binary search of a sorted array.
* Credit: http://php.net/manual/en/function.array-search.php#39115
*
* Tested by [VigilanTor](https://wordpress.org/plugins/vigilantor/) for accuracy and efficiency
*
* @param string $needle String to search for
* @param array $haystack Array to search within
* @return boolean|number false if not found, or index if found
*/
protected function arrayBinarySearch($needle, $haystack)
{
$high = count($haystack);
$low = 0;
while ($high - $low > 1){
$probe = ($high $low) / 2;
if ($haystack[$probe] < $needle){
$low = $probe;
} else{
$high = $probe;
}
}
if ($high == count($haystack) || $haystack[$high] != $needle) {
return false;
} else {
return $high;
}
}
此外,請確保exit()在發送標頭(位置)重定向后呼叫,因為您希望終止請求并立即重定向而不運行其他 PHP 代碼。
if (in_array($needle, $haystack)) {
header('Location: https://www.google.com/');
exit; // Redirect now and don't run any further PHP code
}
最后,如果你想假設所有 Tor 流量都是“糟糕的”,那很好。考慮一條錯誤訊息,而不是在沒有解釋的情況下默默地重定向流量,這是糟糕的用戶體驗。許多人使用 Tor 進行隨意瀏覽,因此您可以毫無理由地從您的站點有效地引導這些用戶。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/395622.html
上一篇:外鍵int陣列C#
下一篇:添加到陣列時變數更改型別
