ASP batch shield IP code

Source: Internet
Author: User

<%
'IP shieldingCode: Www.goudiannao.com

'The set of blocked IP addresses (segments). The asterisk is a wildcard and is usually stored in the configuration file.
Const badipgroup = "123. 123. *. * | 118.73.47 .*"
If isforbidip (badipgroup) = true then
'Response. Write (getip & "Access prohibited from IP addresses ")
Response. Write "<SCRIPT> alert ('[" & getip & "]: You are not welcome here. go to Mars! '); This. Location. href = 'HTTP: // http://www.goudiannao.com/'; </SCRIPT>"
Response. End
End if
'*************************************** *************************
'Parameter vbadip: IP segment to be blocked, IP address set. Use the | symbol to separate multiple IP addresses (segments)
'Return bool: true: the user IP address is in the blocked range; false: otherwise
'*************************************** *************************
Function isforbidip (vbadip)
Dim counter, arrippart, arrbadip, arrbadippart, I, j
Arrbadip = Split (vbadip, "| ")
Arrippart = Split (getip (),".")
For I = 0 to ubound (arrbadip)
Counter = 0
Arrbadippart = Split (arrbadip (I ),".")
For J = 0 to ubound (arrippart)
If (arrbadippart (j) = "*" or CSTR (arrippart (j) = CSTR (arrbadippart (j) then
Counter = counter + 1
End if
Next
If counter = 4 then
Isforbidip = true
Exit Function
End if
Next
Isforbidip = false
End Function

'***************
'Return customer IP Address
'***************
Function getip ()
Dim IP
IP = request. servervariables ("http_x_forwarded_for ")
If IP = "" Then IP = request. servervariables ("remote_addr ")
Getip = IP
End Function
%>

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.