返回列表 回复 发帖

支持非80端口的文件绝对路径的获取脚本程序代码

信息来源:黑客基地

得到当前asp执行文件所在的绝对路径(支持带端口的绝对路径)以'/'结束 
在解决一些XML文档调用时有用.或应用到小偷程序中

程序如下
  1. //powered By Airzen
  2. //qq:39192170
  3. //e_mail:airzen@sohu.com
  4. //date:2004-12-03
  5. //转贴请保留作者信息

  6. FUNCTION GetFullPath()
  7. dim path,host_name,host_port,url_path
  8. path=request.ServerVariables("PATH_INFO")
  9. path=left(path,instrrev(path,"/"))
  10. host_name=request.ServerVariables("SERVER_NAME")
  11. host_port=request.ServerVariables("SERVER_PORT")
  12. if host_port<>"80" then host_name=host_name&":"&host_port
  13. GetFullPath="http://"&host_name&path
  14. End Function

  15. Function GetPage(url)
  16. IF url="" then exit function
  17. Set Retrieval = CreateObject("Microsoft.XMLHTTP")
  18. With Retrieval
  19. .Open "Get", url, False, "", ""
  20. .Send
  21. GetPage = BytesToBstr(.ResponseBody)
  22. End With
  23. Set Retrieval = Nothing
  24. End Function

  25. Function BytesToBstr(body)
  26. dim objstream
  27. set objstream = Server.CreateObject("adodb.stream")
  28. objstream.Type = 1
  29. objstream.Mode =3
  30. objstream.Open
  31. objstream.Write body
  32. objstream.Position = 0
  33. objstream.Type = 2
  34. objstream.Charset = "GB2312"
  35. BytesToBstr = objstream.ReadText
  36. objstream.Close
  37. set objstream = nothing
  38. End Function

  39. Function WriteToFile(fil,wstr)
  40. Dim fso, f
  41. Set fso = Server.CreateObject("Scripting.FileSystemObject")
  42. Set f = fso.CreateTextFile(Server.MapPath(fil),True)
  43. f.Write wstr
  44. Set f = nothing
  45. Set fso = nothing
  46. End function

  47. Function ReadAllTextFile(filespec)
  48. Dim fso, f
  49. Set fso = CreateObject("Scripting.FileSystemObject")
  50. Set f = fso.OpenTextFile(server.MapPath(filespec), 1)
  51. ReadAllTextFile = f.ReadAll
  52. Set f=nothing
  53. Set fso=nothing
  54. End Function

  55. Function IsExists(filespec)
  56. Dim fso
  57. Set fso = CreateObject("Scripting.FileSystemObject")
  58. If (fso.FileExists(server.MapPath(filespec))) Then
  59. IsExists = True
  60. Else
  61. IsExists = False
  62. End If
  63. End Function


  64. MakeXML.ASP
  65. ----------------------------------------------------------------------------------------------------------
  66. <p><a href="?MakeFile=address.xml&SeedFile=listAddress.asp" >点击生成客户XML文件</a>(address.xml)</p>
  67. <p><a href="?MakeFile=brand.xml&SeedFile=listBrand.asp">点击生成产品XML文件</a>(brand.xml)</p>
  68. <!-- #include file="Module/func.asp"-->
  69. <%
  70. '///////////////////////////////////////
  71. '   MakeXML.asp
  72. 'coder   :airzen
  73. 'date :Nov 15,2004
  74. 'descript :MAKE THE XML FILE "Address.xml" "Brand.xml"
  75. 'email :airzen@sohu.com
  76. 'qq   :39192170
  77. 'Create Date:2004 11.5
  78. 'Modified History:2004 11.15
  79. '///////////////////////////////////////

  80. 'on error resume next
  81. SUB MakeXML(byVal make_fileName,byVal seed_ASPfile)
  82. IF IsExists(seed_ASPfile) THEN
  83.   url_path=GetFullPath()&seed_ASPfile
  84. 'response.write url_path

  85. make_content=GetPage(url_path)
  86. call WriteToFile(make_fileName,make_content)

  87. if err.number>0 then
  88.   response.write "<BR>File Generate Failed!"
  89. else
  90.   'response.write make_content
  91.   response.write "<BR>OK!! the File [ <font color=red>"&make_fileName&"</font> ] has Generated!"
  92. end if
  93. ELSE
  94. RESPONSE.WRITE("参数错误")
  95. END IF

  96. END SUB

  97. make_fileName=request.QueryString("MakeFile")
  98. seed_ASPfile=request.QueryString("SeedFile")
  99. IF request.ServerVariables("QUERY_STRING")>"" then
  100. CALL MakeXML(make_fileName,seed_ASPfile)
  101. END IF
  102. %>
复制代码
返回列表