判斷指定IP是否在指定IP段中

2021-08-20 03:59:02 字數 812 閱讀 5429

最近在做乙個訪問控制的功能,只允許指定ip,或者ip段中的ip訪問。

下面方法用來判斷指定ip是否在指定ip段中(已通過測試)。

/**

* 判斷ip是否在某個網段內

*@param $ip

*@param $network

*@return bool

*/function

ipinnetwork

($ip, $network)

return

false;

}

同時在使用中,發現了乙個php內建方法hash_equals(stringa, stringb)用來判斷兩個字串是否想等。文件如下:

/**

* timing attack safe string comparison

*@link

*@param string $known_string the string of known length to compare against

*@param string $user_string the user-supplied string

*@return boolean returnstruewhen the two strings are equal,falseotherwise.

*@since 5.6.0

*/function

hash_equals

($known_string, $user_string) {}

參考:

如何判斷IP位址是否在某個IP段中

sql如何判斷ip位址是否在某個ip段中 環境sqlserver 2008 r2 1.我的表結構 ii id 標識 ii startip 開始ip ii endip 結束ip si id 學校id ii state ip狀態是否檢查過 這是我在程式裡使用的 表名ipinfo 2.建立獲取ip函式 c...

判斷指定目錄是否有檔案

判斷指定目錄是否有檔案 linux 中如何判斷指定目錄下是否有檔案 包括隱藏檔案和符號鏈結 呢?指令碼名 decide blank folder.sh 指令碼內容 shell bin sh whether the specified folder has files,including symbol...

C 判斷指定檔案是否存在

private void button2 click object sender,eventargs e else 注 使用file.exists方法,需要引用 system.io 命名空間 語法 public static bool exists string path 引數 path 型別 sy...