当前位置: 移动技术网 > IT编程>开发语言>.net > 查询某关键词在MSSQL数据库位置的ASP脚本

查询某关键词在MSSQL数据库位置的ASP脚本

2018年10月05日  | 移动技术网IT编程  | 我要评论

康熙来了20130221,王祖蓝快乐大本营,cctv网上商城

oldjun.com

晚上皇子丢给我一段sql语句,功能是:以一个关键字为索引,搜索整个,然后返回那个关键字所在的表名和列名。(很赞...特别是入侵的时候找不到用户名与密码所在的表的时候,如果能直接通过输入admin这个关键词找出字段...省得一个表一个表的看了。)于是根据那段语句,写了个的脚本,方便大家以后搜寻数据库。

整体而言,这段sql只适宜用在小型数据库上,asp中的循环也没效率,大库还是别用了,小库可以考虑。如果是大库的话,请联系皇子要另外一份牛人写的sql查询语句。

代码如下:

<%

confirm a keywords position of a database(which table & which column)
by oldjun()
based on huangzi( sql

server.scripttimeout=999999999
response.buffer =true
on error resume next
keyword=request("keyword")
if keyword="" then
response.write "need keyword!"
response.end
end if
dim conn
set conn = server.createobject("adodb.connection")
dim connstr
connectionstring,pls change!
connstr="driver={sql server};server=localhost;uid=sa;pwd=sa;database=master"
conn.open connstr
conn.execute("create table huangzi_table(id int identity(1,1),biaoid int,biaoname nvarchar(1000))")
conn.execute("insert huangzi_table select [id],[name] from sysobjects where xtype=u")

set rs =conn.execute("select count(id) as tnum from huangzi_table")
tnum=rs("tnum")
rs.close
set rs=nothing
for i=1 to tnum

set rsbiao =conn.execute("select biaoid from huangzi_table where id="&i&"")
biaoid=rsbiao("biaoid")
set rst =conn.execute("select [biaoname] from huangzi_table where biaoid="&biaoid&"")
tname=rst("biaoname")

set rsl=conn.execute("select count([name]) as lnum from syscolumns where id="&biaoid&"")
lnum=rsl("lnum")

for j=1 to lnum

topnum=j-1
set rslie=conn.execute("select top 1 [name] from syscolumns where id="&biaoid&" and [name] not in
(select top "&topnum&" [name] from syscolumns where id="&biaoid&")")
liename=rslie("name")
set rsresult=conn.execute("select top 1 ["&liename&"] from ["&tname&"] where cast(["&liename&"] as nvarchar(1000))="&keyword&"")

if rsresult.bof or rsresult.eof then
response.write "nothing-"&tname&":"&liename
response.write "<br>"
else
result=rsresult(liename)
response.write result&"("&tname&":"&liename&")"
response.write "<br>"
end if

rslie.close
set rslie=nothing
rsresult.close
set rsresult=nothing
next

rsbiao.close
set rsbiao=nothing
rst.close
set rst=nothing
rsl.close
set rsl=nothing
next

conn.execute("drop table huangzi_table")
%>
注:效率很差,使用时可能出现假死, 请耐心等待,大库还是别用了;代码简单,实现的简单功能,没技术含量,留着以后备用;换连接语句的时候有个缓存问题,建议重启下!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网