How to mask IP addresses in ASP code to prevent an IP segment from accessing a Web site

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Often some local business-to-business or business-to-consumer websites are littered with lots of junk information, sharing my solutions:

Add the following code to your ASP page to test the effect:

<%
A collection of masked IP addresses (segments) with an asterisk of wildcard characters, usually stored in a configuration file.
Const Badipgroup = "192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1"

If Isforbidip (badipgroup) = True Then
Response.Write (GetIP & "IP address No Access")
Response.End ()
End If




' parameter vbadip: the IP segment to be screened, the IP address collection, the | symbol to separate multiple IP addresses (segments)


' returns bool:true User IP in the masked range, False vice versa





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 the client 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
%>

This restricts access to the IP segment of the site, and you can set it according to the region's IP segment.

I use this method to prevent foreign users from using rogue software malicious to my site to publish information!

The above content is transferred from (Yi Yuan Network) detailed source please refer to: http://www.05371.com/content/200891013820.html

Panorama survey of 100 internet CEOs in China http://www.admin5.com/article/20080921/105173.shtml

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.