Spark
Spark copied to clipboard
期望能够添加 下载远程文件 和 批量执行的功能
Please make sure of the following things.
- [X] I have read the documentation.
- [X] 我已阅读 文档。
- [X] I'm sure there are no duplicate issues.
- [X] 我确定没有提交和他人重复的issue。
- [X] I'm sure this feature is not implemented.
- [X] 我确定该功能尚未实现。
- [X] I'm sure it's a reasonable and popular requirement.
- [X] 我确定这个需求合理且符合大多数人需要。
Describe the feature / 需求描述
我这边的场景时爬虫,因为一台一台上传执行太困难,所以找到了这个项目,很惊喜
使用过程中发现了一些问题,所以需要能够批量执行的功能。
期望功能:
- 终端下载 指定文件 到 指定位置
- 批量(多终端)启动程序
Suggested solution / 实现思路
No response
Additional information / 附加说明
下面时使用中遇到的问题,可以忽略哈。。
第一个遇到的问题就是 客户端报毒,这个我用了 Linux 下的 upx
加了个壳子绕过了
第二个问题是 要批量执行命令,终端机器系统有 win7 的 不能很好的执行 powershell 脚本,遂用了 vbs, 但是吧。。这东西被 杀软报 Downloader 病毒。。
下载远程文件的功能,本来最初确实在计划中,但是没想到一个好些的UI,所以就搁置了。 批量执行命令的功能,确实不在计划中,如果要做的话,那估计会在新项目里实现了。 客户端报毒,这个自始至终压根没有想过,因为是给我个人的设备使用的,没装杀毒软件,也没这方面的需求。
那我就先这样凑合用吧 >_<
let processScript = `
Sub KillProcess(ByVal ProcessName)
DIM oProcMgmt, oProcess
Set oProcMgmt = GetObject("winmgmts:\\\\.\\root\\cimv2")
Set oProcesses = oProcMgmt.ExecQuery("SELECT * FROM win32_process WHERE name='" & ProcessName & "'")
For each oItem in oProcesses
oItem.terminate()
Next
WScript.Sleep(500)
End Sub
Sub StartProcess(ByVal ExeFile)
Dim Wsh
Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.CurrentDirectory = "${workPath}"
WScript.Sleep(500)
Wsh.Run ExeFile, 0, False
Set Wsh = NoThing
WScript.quit
End Sub
`;
let downloadScript = `Dim WorkPath, Fs
Set Fso = CreateObject("Scripting.FileSystemObject")
WorkPath="${workPath}"
If Not Fso.FolderExists(WorkPath) Then
Fso.CreateFolder(WorkPath)
End If
Function HttpDownload(ByVal remoteUrl, ByVal DistPath)
Set Post = CreateObject("Msxml2.XMLHTTP")
Post.Open "GET", remoteUrl, 0
Post.Send()
Set writer = CreateObject("ADODB.Stream")
writer.Mode = 3
writer.Type = 1
writer.Open
writer.Write(Post.responseBody)
writer.SaveToFile DistPath, 2
writer.Close
End Function
Function readBinaryFile(strPath)
With CreateObject("ADODB.Stream")
.Open
.type = 1
.LoadFromFile(strPath)
readBinaryFile = .Read()
.close()
End With
End Function
Function bytesToHex(aBytes)
Dim hexStr, I
for I = 1 to lenb(aBytes)
hexStr = hex(ascb(midb( (aBytes), I, 1)))
if len(hexstr) = 1 then hexStr = "0" & hexStr
bytesToHex = bytesToHex & hexStr
next
End Function
Function md5sum(aBytes)
Dim MD5: Set MD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
MD5.Initialize()
md5sum = MD5.ComputeHash_2((aBytes))
End Function
Sub UnZip(ByVal myZipFile, ByVal myTargetDir)
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FileExists(myZipFile) Then
Exit Sub
ElseIf fso.GetExtensionName(myZipFile) <> "zip" Then
Exit Sub
ElseIf NOT fso.FolderExists(myTargetDir) Then
fso.CreateFolder(myTargetDir)
End If
Set objShell = CreateObject("Shell.Application")
Set objSource = objShell.NameSpace(myZipFile)
Set objFolderItem = objSource.Items()
Set objTarget = objShell.NameSpace(myTargetDir)
intOptions = 256
objTarget.CopyHere objFolderItem, intOptions
End Sub
REM 文件有更改,删除 重新下载
If Fso.FileExists("${zipFullFilePath}") Then
zipMd5 = bytesToHex(md5sum(readBinaryFile("${zipFullFilePath}")))
If zipMd5 <> "${zipFileMd5sum}" Then
Fso.DeleteFile("${zipFullFilePath}")
Call HttpDownload ("${zipRemoteUrl}", "${zipFullFilePath}")
End If
Else
Call HttpDownload ("${zipRemoteUrl}", "${zipFullFilePath}")
End If
REM 文件有更改,删除 解压
If Fso.FileExists("${exeFullFilePath}") Then
exeMd5 = bytesToHex(md5sum(readBinaryFile("${exeFullFilePath}")))
If exeMd5 <> "${exeFileMd5sum}" Then
Fso.DeleteFile("${exeFullFilePath}")
Call UnZip ("${zipFullFilePath}", WorkPath)
End If
Else
Call UnZip ("${zipFullFilePath}", WorkPath)
End If
`;
result = await client.processSearch(item, "wscript.exe")
if (result.length > 0) {
console.log(item.substring(0, 8) +" 更新程序中!")
} else {
result = await client.fileExists(item, vbCommon.defines.exeFullFilePath)
if (result) {
result = await client.processSearch(item, vbCommon.defines.exeFileName)
console.log(item.substring(0, 8) +" 当前启动数:" + result.length)
if (result.length < processNum) {
let startNum = processNum - result.length;
while (startNum > 0) {
await client.runScript(item, vbscript);
console.log(item.substring(0, 8) +" 启动爬虫程序!")
await sleep(1);
startNum --;
}
}
} else {
}
}