动网的ip数据库怎么使用啊?

cakecai 2005-03-31 04:05:11
好像是ip1 --- ip2是个范围。那么怎样把实际的ip转化成对应数据库中的整数?
...全文
238 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
satans18 2005-03-31
  • 打赏
  • 举报
回复
<%
dim ipdb,ipconn,stop_ip,un_ip,rs_ip
un_ip=0
ipdb=Server.MapPath("stopip.mdb") ' 在此处更改数据库名称及路径
set ipconn=Server.CreateObject("ADODB.Connection")
ipconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ipdb

stop_ip= Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If stop_ip="" Then stop_ip= Request.ServerVariables("REMOTE_ADDR")
call ynip(stop_ip)

if un_ip=0 then
set rs_ip=ipconn.execute("select viw From stopip where viw<>0 and ("& cip(stop_ip) &" between oneip and endip)",0,1)
if not rs_ip.eof then
if rs_ip("viw")=1 then Response.write"网站数据维护,请稍后再来<br>"
if rs_ip("viw")=2 then Response.write"你的IP被禁止访问<br>"
rs_ip.close
set rs_ip=nothing
ipconn.close
set ipconn=nothing
Response.end
end if
rs_ip.close
set rs_ip=nothing
end if

sub ynip(uip)
dim tip
tip = split(uip,".")
if not IsArray(tip) then un_ip=1
if UBound(tip)<3 then un_ip=1
if Not IsNumeric(tip(0)) or Not IsNumeric(tip(1)) or Not IsNumeric(tip(2)) or Not IsNumeric(tip(3)) then un_ip=1
if cint(tip(0))>255 or cint(tip(1))>255 or cint(tip(2))>255 or cint(tip(3))>255 then un_ip=1
end sub
function cip(sip)
dim tip
'tip=cstr(sip)
'sip1=left(tip,cint(instr(tip,".")-1))
'tip=mid(tip,cint(instr(tip,".")+1))
'sip2=left(tip,cint(instr(tip,".")-1))
'tip=mid(tip,cint(instr(tip,".")+1))
'sip3=left(tip,cint(instr(tip,".")-1))
'sip4=mid(tip,cint(instr(tip,".")+1))
'if cint(sip1)<128 then
'cip=cint(sip1)*256*256*256+cint(sip2)*256*256+cint(sip3)*256+cint(sip4)
'else
'cip=cint(sip1)*256*256*256+cint(sip2)*256*256+cint(sip3)*256+cint(sip4)-4294967296
'end if
tip = split(sip,".")
if cint(tip(0))<128 then
cip=cint(tip(0))*256*256*256+cint(tip(1))*256*256+cint(tip(2))*256+cint(tip(3))
else
cip=cint(tip(0))*256*256*256+cint(tip(1))*256*256+cint(tip(2))*256+cint(tip(3))-4294967296
end if
end function
ipconn.close
set ipconn=nothing
%>
satans18 2005-03-31
  • 打赏
  • 举报
回复
IP段限制及管理被封IP代码



1-------------------------------------------stopip.asp-------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
dim webname,pw
pw=request("pw")
if pw="admin" then Session("stopip")="1"
if Request.QueryString("cls")="exit" then Session("stopip")=""

'''''''###############################################################
if Session("stopip")<>"" then
dim ipdb,ipconn,ipid,ipcls
ipdb=Server.MapPath("stopip.mdb") ' 在此处更改数据库名称及路径
set ipconn=Server.CreateObject("ADODB.Connection")
ipconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ipdb

ipid=Request.QueryString("id")
ipcls=Request.QueryString("cls")


Select case ipcls
case ""

case "del"
ipconn.execute("Delete From stopip Where id="&ipid)
case "jd0"
ipconn.execute("Update stopip set viw=0 Where id="&ipid)
case "jd1"
ipconn.execute("Update stopip set viw=1 Where id="&ipid)
case "jd2"
ipconn.execute("Update stopip set viw=2 Where id="&ipid)
end Select

if Request.Form("Submit")="提交" then
dim oneip,endip
oneip=trim(Request.Form("oneip"))
endip=trim(Request.Form("endip"))
call ynip(oneip)
call ynip(endip)
Set rs = Server.CreateObject("ADODB.RecordSet")
sql="Select * from stopip"
Rs.open sql,ipconn,2,3
Rs.addnew
rs("oneip")=cip(oneip)
rs("endip")=cip(endip)
rs("ip1")=oneip
rs("ip2")=endip
rs("rdate")=now()
rs("viw")=1
rs.update
rs.close
end if
end if
stop_ip= Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If stop_ip= "" Then stop_ip= Request.ServerVariables("REMOTE_ADDR")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>IP管理器</title>
<style type="text/css">
<!--
.unnamed1 {
font-size: 12px;
line-height: 20px;
}
-->
</style>
</head>

<body>
<% If Session("stopip")="" Then %>
<form name="form1" method="post" action="stopip.asp">
<TABLE width="600" height=0 border=1 align=center cellPadding=3 cellSpacing=0 class="unnamed1" style="border-collapse:collapse" >
<tr bgcolor="#E4F2FA">
<td colspan="3">
<div align="center">登录 <%=stop_ip%></div></td>
</tr>
<tr>
<td width="19%"><div align="right"></div></td>
<td width="30%"><input name="pw" type="password" id="pw"></td>
<td width="51%"> </td>
</tr>
<tr>
<td> </td>
<td colspan="2"><input type="submit" name="Submit1" value="提交"></td>
</tr>
</table>
<br>
</form>
<%
Response.End
end if %>

<form name="form1" method="post" action="">
<TABLE width="600" height=0 border=1 align=center cellPadding=3 cellSpacing=0 class="unnamed1" style="border-collapse:collapse" >
<tr bgcolor="#E4F2FA">
<td colspan="3">
<div align="center">IP管理 <%=stop_ip%></div></td>
</tr>
<tr>
<td width="19%"><div align="right">IP段:</div></td>
<td width="30%"><input name="oneip" type="text" id="oneip"></td>
<td width="51%"><input name="endip" type="text" id="endip"></td>
</tr>
<tr>
<td> </td>
<td colspan="2"><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>
<br>
</form>
<% set rs=ipconn.execute("select * from stopip")%>
<TABLE width="600" height=0 border=1 align=center cellPadding=0 cellSpacing=0 class="unnamed1" style="border-collapse:collapse" >
<TBODY>
<TR >
<TD height=25 bgcolor="#E4F2FA" class="jd_title" >
<div align="center">被封IP信息</div></TD>
</TR>
<TR>
<TD align=middle valign="top" > <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="unnamed1">
<tr>
<td>状态</td>
<td>起始</td>
<td>终止</td>
<td>时间</td>
<td>操作</td>
</tr>
<tr>
<td height="2" colspan="5" bgcolor="#E4F2FA" class="jd_title"></td>
</tr>
<% ipi=0
do while not rs.eof
ipi=ipi+1 %>
<tr>
<td>
<%
if rs("viw")=1 then
Response.write("<font color='#FF9900'>")
end if
if rs("viw")=0 then
Response.write("<font color='#009900'>")
end if
if rs("viw")=2 then
Response.write("<font color='#FF0000'>")
end if
Response.write("●</font>")
%>
</td>
<td><%=rs("ip1")%></td>
<td><%=rs("ip2")%></td>
<td><%=rs("rdate")%></td>
<td><a href="stopip.asp?cls=del&id=<%=rs("id")%>" onClick="return confirm('删除一个IP段?!\n\n该操作不可恢复!可以设为开通,保留这个段.\n\n要删除请按[确定]\n\n不小心按错按[取消]反回!')">删除</a>
<a href="stopip.asp?cls=jd0&id=<%=rs("id")%>">开通</a>
<a href="stopip.asp?cls=jd1&id=<%=rs("id")%>">维护</a>
<a href="stopip.asp?cls=jd2&id=<%=rs("id")%>">禁止</a>
</td>
</tr>
<tr>
<td height="1" class="jd_title" colspan="5" bgcolor="#E4F2FA"></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
ipconn.close
set ipconn=nothing
%>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"><div align="center"><font color="#009900">●开通 </font><font color="#FF9900">●维护中</font>
<font color="#FF0000"> ●禁</font></div></td>
</tr>
</table>
</TD>
</TR>
</TBODY>
</TABLE>
<div align="center"><br>
<a href="stopip.asp?cls=exit">退出</a><br>
</div>
</body>
</html>
<% ' IP算法
function cip(sip)
tip=cstr(sip)
sip1=left(tip,cint(instr(tip,".")-1))
tip=mid(tip,cint(instr(tip,".")+1))
sip2=left(tip,cint(instr(tip,".")-1))
tip=mid(tip,cint(instr(tip,".")+1))
sip3=left(tip,cint(instr(tip,".")-1))
sip4=mid(tip,cint(instr(tip,".")+1))
if cint(sip1)<128 then
cip=cint(sip1)*256*256*256+cint(sip2)*256*256+cint(sip3)*256+cint(sip4)
else
cip=cint(sip1)*256*256*256+cint(sip2)*256*256+cint(sip3)*256+cint(sip4)-4294967296
end if
end function

sub eorr()
Response.Write "<script language=java script>alert(""请输入正确的IP"");location.href=""stopip.asp"";</script>"
Response.End
end sub
sub ynip(uip)
dim tip
tip = split(uip,".")
if not IsArray(tip) then call eorr()
if UBound(tip)<3 then call eorr()
if Not IsNumeric(tip(0)) or Not IsNumeric(tip(1)) or Not IsNumeric(tip(2)) or Not IsNumeric(tip(3)) then call eorr()
if cint(tip(0))>255 or cint(tip(1))>255 or cint(tip(2))>255 or cint(tip(3))>255 then call eorr()
end sub
%>
satans18 2005-03-31
  • 打赏
  • 举报
回复
爱搜不搜 -_-
cakecai 2005-03-31
  • 打赏
  • 举报
回复
两位的答案好像有差别啊。
anddytang 2005-03-31
  • 打赏
  • 举报
回复
192.168.0.1转换为192*255*255*255+168*255*255+0*255+1
mjpclab 2005-03-31
  • 打赏
  • 举报
回复
例如a.b.c.c
a*&H1000000 + b*&H10000 + c*&H100 + d

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧