|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
asp是基于web的一种编程技术,可以说是cgi的一种。它可以完成以往cgi程序的所有功能,如计数器、留言簿、公告板、聊天室等等。ThisarticlepresentsasimplewaytopinganaddressandgettheresultsofthepingusingASP.TheideawassuppliedbyBartSilverstein.
First,a.BATfileneedstobecreatedthatwillberunfromtheActiveServerPage.LetscallthisfileDoPing.BAT.Itwillcontainonlyonestatement,whichwillpingapassedinIPaddress.HereisthecodeforDoPing.BAT:
ping-a%1>d:INetPubcgi-bin\%2.txt
Thiswill,ifyoucanttell,pingtheaddresspassedinasthefirstcommandlineargument(%1),andredirecttheresultstoatextfilenamedhythesecondcommandlineargument(%2).Now,letslookhowwewouldcallthisfromanASPfile:
<%
SetFileSys=Server.CreateObject("Scripting.FileSystemObject")
FileName=FileSys.GetTempName
SetWShShell=Server.CreateObject("WScript.Shell")
IP="204.123.54.1"orwhateveryouwanttoping
RetCode=WShShell.Run("d:Inetpubcgi-binDoPing.bat"&IP&""&FileName,1,True)
ifRetCode=0Then
Therewerenoerrors
else
Response.Redirect"PingErrors.htm"
endif
SetTextFile=FileSys.OpenTextFile("d:InetPubcgi-bin"&FileName&".txt",1)
TextBuffer=TextFile.ReadAll
Fori=1toLen(TextBuffer)
IfMid(TextBuffer,i,1)=chr(13)Then
Response.Write("<BR>")
else
Response.Write(Mid(TextBuffer,i,1))
endif
Next
TextFile.Close
FileSys.DeleteFile"d:Inetpubcgi-bin"&FileName&".txt"
%>
Beforeyougohogwildandimplementthiscodeorusesimilartechniquesonyoursite,thereareafewthingsyoushouldbewaryof.Fromasecutirystandpoint,thisisreallydangerous,foranytimeyouletsomeonerunanapplicationonyourserverthereisalwaysthepotentialthatitwillcomebacktohauntyou.Onesuggestiontolessenthethreat:makeaseparatefolderwithnoscriptorexecutepriviledges,andhaveyourDoPing.batoutputitsresultstothatfolder.
Ihopethisarticlewasinformativeaninteresting.HappyProgramming!
asp,你就只能等着微软给你解决,它不乐意你就只好悲催。而且asp跑在windows服务器上,windows服务器跟linux比起来简直弱爆了! |
|