0

アプリケーションからメールを送信する IP アドレスの一部を除外しています。ここでは、web.config ファイルにカスタム タグを作成しました。

<configSections>
  <sectionGroup name="ExcludeIPAddressListSectionGroup">
    <section name="IPAddressListSection" type="CustomConfigurationHandler.CustomConfiguration, CustomConfigurationHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowLocation="true" allowDefinition="Everywhere"/>
  </sectionGroup>
</configSections>

<ExcludeIPAddressListSectionGroup>
  <IPAddressListSection>
      <ExcludedList1 Range="StartingIP=192.168.185.1; EndingIP=192.168.185.50" ></ExcludedList1>
      <ExcludedList2 Range="StartingIP=192.168.185.51;EndingIP=192.168.185.51" ></ExcludedList2>
  </IPAddressListSection>
</ExcludeIPAddressListSectionGroup>

セクション ExcludeIPAddressListSectionGroup を作成し、それらの IP を除外する範囲を指定しました

このようにweb.configからカスタムタグを読んでいます

 Hashtable config = (Hashtable)ConfigurationManager.GetSection("ExcludeIPAddressListSectionGroup/IPAddressListSection");
 foreach (DictionaryEntry deKey in config)
 {
     Hashtable attribs = (Hashtable)deKey.Value;
     foreach (DictionaryEntry deAttrib in attribs)
     {
         string range = deAttrib.Value.ToString();
         string[] range_arr = range.Split(';');

         foreach (string range_str in range_arr)
         {
             Response.Write(range_str+"<br>");
         }
     }
 }

文字列をフォーマットし、開始 IP と終了 IP をこの関数に渡す必要があります bool Between(long value, long left, long right)

4

1 に答える 1

0

次のコードを使用します。IPV4 で動作します。

        List<string> lstIPValues = new List<string>();
        foreach (string range_str in range_arr)
        {
             //again split to get ragne value into List of string.
            string[] ipValues = range_str.Split('=');
            lstIPValues.Add(ipValues[1]);    
        }
        Between(valueToBeChecked,, BitConverter.ToInt64(IPAddress.Parse(lstIPValues[0]).GetAddressBytes(), 0), BitConverter.ToInt64(IPAddress.Parse(lstIPValues[1]).GetAddressBytes(), 0));
于 2013-10-08T09:28:04.453 に答える