Code for implementing IP address access restrictions using ASP code
Source: Internet
Author: User
This was previously written in ASP. I wanted to change it to ASP.net. Later I wanted everyone to understand the algorithm. The key to IP address comparison is the linearity of IP addresses. The following is the code.
Copy codeThe Code is as follows: 'IP address that can be accessed
'2017. 7.44.0-218.7.45.253
'61. 180.240.0-61.180.240.253
'192. 118.208.0-202.118.223.253
'
'2017. 7.44.0 218
'2017. 7.45.253 218
'
'61. 180.240.0 1035268095
'61. 180.240.253 1035268348
'
'1970. 118.208.0 202
'192. 118.223.253 202
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 address is invalid! ")
Response. End ()
Else
Response. write ("your ip address is valid ")
End if
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service