Fuhome未来之家物联网fuhome.net 远程控制设备物联网交流社区

 找回密码
 
搜索
热搜: 活动 交友 discuz
查看: 6407|回复: 0

用于测试post上传图片的小脚本(cmd,vbs),源码

[复制链接]

4

主题

116

威望

70

贡献

论坛元老

Rank: 8Rank: 8

积分
2031
发表于 2017-8-18 12:29:32 | 显示全部楼层 |阅读模式
原理很简单nircmd.exe savescreenshot "d.jpg"截图
post.vbs  上传图片(需要修改)

运行测试.cmd  负责循环调用工具nircmd.exe进行截图,再运行post.vbs发送图片
该脚本可实现实时桌面
源码
post.vbs
  1. '标题: VBS模拟POST上传文件
  2. '作者: Demon
  3. '链接: http://demon.tw/programming/vbs-post-file.html
  4. '版权: 本博客的所有文章,都遵守“署名-非商业性使用-相同方式共享 2.5 中国大陆”协议条款。

  5. '改写自CSDN上的一个ASP中模拟form上传文件,即(multipart/form-data)的表单的程序。
  6. 'XML Upload Class
  7. Class XMLUpload
  8.     Private xmlHttp
  9.     Private objTemp
  10.     Private adTypeBinary, adTypeText
  11.     Private strCharset, strBoundary

  12.     Private Sub Class_Initialize()
  13.         adTypeBinary = 1
  14.         adTypeText = 2
  15.         Set xmlHttp = CreateObject("Msxml2.XMLHTTP")
  16.         Set objTemp = CreateObject("ADODB.Stream")
  17.         objTemp.Type = adTypeBinary
  18.         objTemp.Open
  19.         strCharset = "utf-8"
  20.         strBoundary = GetBoundary()
  21.     End Sub

  22.     Private Sub Class_Terminate()
  23.         objTemp.Close
  24.         Set objTemp = Nothing
  25.         Set xmlHttp = Nothing
  26.     End Sub

  27.     '指定字符集的字符串转字节数组
  28.     Public Function StringToBytes(ByVal strData, ByVal strCharset)
  29.         Dim objFile
  30.         Set objFile = CreateObject("ADODB.Stream")
  31.         objFile.Type = adTypeText
  32.         objFile.Charset = strCharset
  33.         objFile.Open
  34.         objFile.WriteText strData
  35.         objFile.Position = 0
  36.         objFile.Type = adTypeBinary
  37.         If UCase(strCharset) = "UNICODE" Then
  38.             objFile.Position = 2 'delete UNICODE BOM
  39.         ElseIf UCase(strCharset) = "UTF-8" Then
  40.             objFile.Position = 3 'delete UTF-8 BOM
  41.         End If
  42.         StringToBytes = objFile.Read(-1)
  43.         objFile.Close
  44.         Set objFile = Nothing
  45.     End Function

  46.     '获取文件内容的字节数组
  47.     Private Function GetFileBinary(ByVal strPath)
  48.         Dim objFile
  49.         Set objFile = CreateObject("ADODB.Stream")
  50.         objFile.Type = adTypeBinary
  51.         objFile.Open
  52.         objFile.LoadFromFile strPath
  53.         GetFileBinary = objFile.Read(-1)
  54.         objFile.Close
  55.         Set objFile = Nothing
  56.     End Function

  57.     '获取自定义的表单数据分界线
  58.     Private Function GetBoundary()
  59.         Dim ret(12)
  60.         Dim table
  61.         Dim i
  62.         table = "abcdefghijklmnopqrstuvwxzy0123456789"
  63.         Randomize
  64.         For i = 0 To UBound(ret)
  65.             ret(i) = Mid(table, Int(Rnd() * Len(table) + 1), 1)
  66.         Next
  67.         GetBoundary = "---------------------------" & Join(ret, Empty)
  68.     End Function

  69.     '设置上传使用的字符集
  70.     Public Property Let Charset(ByVal strValue)
  71.         strCharset = strValue
  72.     End Property

  73.     '添加文本域的名称和值
  74.     Public Sub AddForm(ByVal strName, ByVal strValue)
  75.         Dim tmp
  76.         tmp = "\r\n--$1\r\nContent-Disposition: form-data; name=""$2""\r\n\r\n$3"
  77.         tmp = Replace(tmp, "\r\n", vbCrLf)
  78.         tmp = Replace(tmp, "$1", strBoundary)
  79.         tmp = Replace(tmp, "$2", strName)
  80.         tmp = Replace(tmp, "$3", strValue)
  81.         objTemp.Write StringToBytes(tmp, strCharset)
  82.     End Sub

  83.     '设置文件域的名称/文件名称/文件MIME类型/文件路径或文件字节数组
  84.     Public Sub AddFile(ByVal strName, ByVal strFileName, ByVal strFileType, ByVal strFilePath)
  85.         Dim tmp
  86.         tmp = "\r\n--$1\r\nContent-Disposition: form-data; name=""$2""; filename=""$3""\r\nContent-Type: $4\r\n\r\n"
  87.         tmp = Replace(tmp, "\r\n", vbCrLf)
  88.         tmp = Replace(tmp, "$1", strBoundary)
  89.         tmp = Replace(tmp, "$2", strName)
  90.         tmp = Replace(tmp, "$3", strFileName)
  91.         tmp = Replace(tmp, "$4", strFileType)
  92.         objTemp.Write StringToBytes(tmp, strCharset)
  93.         objTemp.Write GetFileBinary(strFilePath)
  94.     End Sub

  95.     '设置multipart/form-data结束标记
  96.     Private Sub AddEnd()
  97.         Dim tmp
  98.         tmp = "\r\n--$1--\r\n"
  99.         tmp = Replace(tmp, "\r\n", vbCrLf)
  100.         tmp = Replace(tmp, "$1", strBoundary)
  101.         objTemp.Write StringToBytes(tmp, strCharset)
  102.         objTemp.Position = 2
  103.     End Sub

  104.     '上传到指定的URL,并返回服务器应答
  105.     Public Function Upload(ByVal strURL)
  106.         Call AddEnd
  107.         xmlHttp.Open "POST", strURL, False
  108.         xmlHttp.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & strBoundary
  109.         'xmlHttp.setRequestHeader "Content-Length", objTemp.size
  110.         xmlHttp.Send objTemp
  111.         Upload = xmlHttp.responseText
  112.     End Function
  113. End Class

  114. Dim UploadData
  115. Set UploadData = New XMLUpload
  116. UploadData.Charset = "utf-8"
  117. 'UploadData.AddForm "content", "Hello world" '文本域的名称和内容
  118. 'UploadData.AddFile "file", "test.jpg", "image/jpg", "test.jpg"
  119. UploadData.AddForm "sbid", "0000000000"'设备ID
  120. UploadData.AddForm "sbmm", "0000000000000000"'16位加密密码
  121. UploadData.AddForm "feelid", "101"'传感器ID
  122. UploadData.AddFile "uploadfile", "d.jpg", "image/jpg", "d.jpg"
  123. UploadData.Upload("http://fuhome.net/api/desktop/")
  124. Set UploadData = Nothing
复制代码



运行测试.cmd
  1. :go
  2. nircmd savescreenshot "d.jpg"
  3. start /wait post.vbs
  4. goto go
复制代码


压缩包
利用vbs、nircmd、cmd,post上传图片.zip (44.15 KB, 下载次数: 2118)
回复

使用道具 举报

您需要登录后才可以回帖 登录 |

本版积分规则

小黑屋|手机版|Archiver|Fuhome未来之家物联网  

GMT+8, 2020-9-22 00:25 , Processed in 0.043183 second(s), 26 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表