This is previously written in ASP, I would like to change into asp.net to everyone, and then think we can read the algorithm on the line. The key of IP alignment is the linearization of IP address, the following is the code.
Copy Code code as follows:
' Access to IP
' 218.7.44.0-218.7.45.253
' 61.180.240.0-61.180.240.253
' 202.118.208.0-202.118.223.253
'
' 218.7.44.0 3657903103
' 218.7.45.253 3657903612
'
' 61.180.240.0 1035268095
' 61.180.240.253 1035268348
'
' 202.118.208.0 3396784127
' 202.118.223.253 3396788220
Ip=request.servervariables ("REMOTE_ADDR")
Sip=split (IP, ".")
Num=cint (SIP (0)) *256*256*256+cint (SIP (1)) *256*256+cint (SIP (2)) *256+cint (SIP (3))-1
Response.Write (IP)
Response.Write ("<br>")
if (num>=3657903103 and num<=3657903612) or (num>=1035268095 and num<=1035268348)
or (num>=3396784127 and num<=3396788220)) then
Response.Write ("Sorry, your IP is not legal!") ")
Response. End ()
Else
Response.Write ("Your IP is legitimate")
End If