inicio mail me! sindicaci;ón

Whether does some IP attribute some net with Asp judgement paragraph additional kind of algorithm

Occasionally we need to judge certain IP address to whether attribute a net paragraph, in order to decide this user whether visit system.

The IP that for instance the user logs onto is 218.6.7.7, and our program must judge him to whether belong to 218.6.0.0/16 this net paragraph (among them / 16 it is new child the expression that net attack by surprise piles up means, be equivalent to 255.255.0.0) .

Want to realize such function, popular now algorithm is will 218.6.0.0 and 218.6.7.7 by 256 into make conversion become 10 into make hand-in-hand travel reach quite, if calculate first,go out 218.6.0.0 and of 218.6.255.255 decimal:

218×256×256×256 6×256×256=3657826304,

218×256×256×256 6×256×256 255

×256×256 255=3657891839.

Calculate again piece of 218.6.7.7 10 into

: 218×256×256×256 6×256×256 7×256 7=

3657828103, compare again finally 3657828103 whether be more than be equal to 3657826304 and be less than be equal to 3657891839. But have a problem apparently, computational capacity is very much, the value is very great, if IP address is 61 begin not bad, if be of 218 begin, this will cause data to spill over and make mistake.

Compare IP to whether attribute some net actually paragraph, best means is IP and net paragraph turn respectively for 32 binary systems, the network share that compares them again is same OK.asp itself does not have a moving function, want to realize this to only we come true by hand so, specific as follows:

‘ will be decimal turn for binary stringFunction Dec2bin(octNumber)Vara=octNumberDoDec2bin=cstr(vara Mod 2)&Dec2binVara=vara \ 2Loop Until Vara=0End Function

‘ is binary string fill 8Function Pad(str)Pad=right(”00000000 “&Str, 8)End Function

Whether is ‘ judgement an IP addressFunction IsIp(ipadd)IsIp=falseSet OReg=new RegExpOReg.IgnoreCase=trueOReg.global=trueOReg.Pattern= “(\d{1, 4}\ . \d{1, 4}\ . \d{1, 4}\ . \d{1, 4}) |

(\d{1, 4}\ . \d{1, 4}\ . \d{1, 4}\ . \d{1, 4}\/\d{1, 2}) “If OReg.test(ipadd) Then IsIp=trueSet OReg=nothingEnd Function

‘ among them UserIP is the IP that we should detect

‘NetIP is the net that should detect paragraph or a certain IP, will indicate a net with Xxx.xxx.xxx.xxx/N paragraph, among them N expresses child net attack by surprise piles up digit

‘ is noted, this program is round-the-world 10 thousand dimension start a program formerly, if you want,reprint so, withhold provenance information please, thank.

‘ programming: Major of? of the leech that be not Nao offers a domain name to register, fictitious lead plane serves

‘ network address: HTtp://www.netInter.cn

‘ above information and article text are impartible cut one share, if you want,reprint article chapter so, you must withhold above information.

In all 2 pages: On one page 1[2] Issue one page

Bookmark:Digg Del.icio.us Reddit

Leave a Comment