0

IP アドレスが IP の範囲内にあるかどうかを確認する必要があります。

たとえば、10-20.3.5.6 には IP が次のように含まれます。

10.3.5.6 11.3.5.6 . . . 20.3.5.6

次のことを知る必要があります。

1) 1-10.0-255.0.0-255 は、DB にある IP 範囲です。IP「10.0.7.8」が上記の指定範囲内にあるかどうかを確認する必要があります。

2) DB にある別のシナリオを 10-20.10-20.10-20.10-20 とします。範囲 10-20.10.10-30.10-50 のいずれかの IP が上記の範囲に該当するかどうかを確認する必要がありますか?

4

1 に答える 1

0

このようなことを試してみましょう...

 ArrayList<String> IPlist = getIPTable(); //IPTable has entries
 Pair IPranges[4] = new Pair[4]();

 //Pair isa class that holds two things, like numbers;

 //parse your DB entries into the IPranges
 IPranges[0].low = 10; IPranges[0].hi = 20;
 IPranges[1].low = 3; IPranges[1].hi = 3;
 IPranges[2].low = 5; IPranges[2].hi = 5;
 IPranges[3].low = 6; IPranges[3].hi = 6;

 for(String IP : IPlist)
 { 
      String octet[4]; //read the octets in the String[] octet using substring();
      boolean continue = true; 
      for(int i = 0 ; i < 4 && continue; i++)
          if(Integer.parseInt(octet[i]) >= IPtable[i].low && Integer.parseInt(octet[i]) <= IPtable[i].hi)
          {
              //this is good, do stuff here
          }
          else
             continue = false;  //the IP failed to pass the filter, no need to process the rest of it
         //safely add the IP to the lsit of valid IPs.
       validIP.add(IP);
}



private class Pair
{
    public int low, hi;

    public Pair(int low, int hi)
    {
        this.low = low; this.hi = hi;
    }
} //feel free to extend this class to do the checking for you.
于 2012-08-16T15:37:13.163 に答える