aspnet拒绝ip访问_Asp限制IP访问 阻止某一个IP段禁止访问本站的代码

''获取访问者的地址

ip=Request.ServerVariables("REMOTE_ADDR")

''允许的IP地址段为10.0.0.0~10.68.63.255

allowip1="10.0.0.0"

allowip2="10.68.10.71"

response.writecheckip(ip,allowip1,allowip2)

functioncheckip(ip,allowip1,allowip2)

dimcheck(4)

checkip=false

ipstr=split(ip,".")

allow1=split(allowip1,".")

allow2=split(allowip2,".")

ifcint(allow1(0))>cint(allow2(0))then''判断IP地址段是否合法

response.write"禁止访问"

exitfunction

endif

fori=0toubound(ipstr)

ifcint(allow1(i))

ifcint(allow1(i))=cint(ipstr(i))then

check(i)=true

checkip=true

exitfor

else

ifcint(ipstr(i))

check(i)=true

checkip=true

exitfor

else

ifcint(ipstr(i))>cint(allow2(i))then

check(i)=false

checkip=false

exitfor

else

check(i)=true

checkip=true

endif

endif

endif

else

ifcint(allow1(i))>cint(ipstr(i))orcint(allow1(i))

check(i)=false

checkip=false

ifi<>ubound(ipstr)then

exitfor

endif

else

check(i)=true

endif

endif

next

if(check(0)=trueandcheck(1)=trueandcheck(2)=trueandcheck(3)=false)and(cint(allow2(2))>cint(ipstr(2)))then

checkip=true

endif

endfunction

%>

把以下代码加入到你的ASP页面就可以测试到效果了:

'受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。

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地址禁止访问")

Response.End()

End If

'参数vBadIP:要屏蔽的IP段,IP地址集合,用|符号分隔多个IP地址(段)

'返回Bool:True用户IP在被屏蔽范围,False 反之

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

''返回客户IP地址

Function GetIP()

Dim IP

IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR")

GetIP = IP

End Function

%>

这样就可以限制网站访问的IP段了,你可以根据地区的IP段来设置。

我就是用这个方法防止外地用户使用流氓软件恶意到我网站发布信息的!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是使用Senparc.Weixin.AspNet写一个微信分享接口的步骤: 1. 安装Senparc.Weixin.AspNet 使用NuGet安装Senparc.Weixin.AspNet,可以在Visual Studio的NuGet包管理器中搜索并安装。 2. 配置微信公众号信息 在Web.config文件中配置微信公众号的AppId、AppSecret等信息,以便进行微信授权和分享。例如: ```xml <appSettings> <add key="WeixinAppId" value="your_appid" /> <add key="WeixinAppSecret" value="your_appsecret" /> <add key="WeixinToken" value="your_token" /> <add key="WeixinEncodingAESKey" value="your_encodingAESKey" /> </appSettings> ``` 3. 创建分享接口 创建一个Controller,并添加一个Action来处理分享请求,例如: ```csharp public class WeixinShareController : Controller { [HttpPost] public ActionResult Share(string url) { var jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(WeixinConfig.WeixinAppId, WeixinConfig.WeixinAppSecret, url); return Json(jssdkUiPackage); } } ``` 在Action中,调用Senparc.Weixin.MP.Helpers.JSSDKHelper.GetJsSdkUiPackage方法获取JSSDK的UiPackage信息,并返回Json格式的结果。 4. 在前端页面中调用分享接口 在前端页面中,通过Ajax调用分享接口获取分享信息,例如: ```javascript $.post('/WeixinShare/Share', { url: location.href }, function (result) { wx.config({ debug: false, appId: result.appId, timestamp: result.timestamp, nonceStr: result.nonceStr, signature: result.signature, jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] }); wx.ready(function () { wx.onMenuShareTimeline({ title: '分享标题', link: location.href, imgUrl: '分享图片地址' }); wx.onMenuShareAppMessage({ title: '分享标题', desc: '分享描述', link: location.href, imgUrl: '分享图片地址' }); }); }); ``` 在页面加载完成后,通过Ajax调用分享接口获取分享信息,然后使用wx.config和wx.ready方法进行微信JSSDK的初始化和分享设置。 以上就是使用Senparc.Weixin.AspNet写一个微信分享接口的基本流程,建议根据自己的业务需求进行更加详细的配置和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值