|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『楼 主』:
迅雷下载后关机
使用 LLM 解释/回答一下
多谢各位的建议,判断的准确度已经进一步了。
这个P处理用处不大,在这只做参考。。
代码是以迅雷5写的,如果你不是用迅雷5的,请把名字改成你的下载器名。已经
测试过其他下载器同样可以,只要把下载器的名字替换掉以下的Thunder5.exe
即可。
把以下代码保存为“迅雷关机监控.bat”:
@echo off&setlocal EnableDelayedExpansion
::迅雷关机监控 code by gool123456 @ 2010
::============================
mode con cols=50 lines=10
title 迅雷关机监控 code by gool123456
set /p dir_=把需要监控的文件夹拖入(当前文件夹直接回车):
if "%dir_%"=="" set "dir_=%cd%"
set "dir_=%dir_:"=%"
cd.>"c:\temp.txt"
dir "%dir_%" /a-d /b>>"c:\temp.txt"
for /f "delims=:" %%a in ('dir "%dir_%" /a-d /b^|findstr /n .') do (set /a "ge=%%a")
:begin
echo 下载未进行.等待开始...
ping 127.1 -n 3 >nul&cls
:jj
for /f "delims=:" %%b in ('dir "%dir_%" /a-d /b^|findstr /n .') do (set /a "ge1=%%b")
if !ge1! GTR !ge! goto :xiazai
if !ge1! equ !ge! goto :begin
:xiazai
ping 127.1 -n 3 >nul&cls
<nul set/p= 当前时间 : %time% &set/p=已耗时:%tm%秒<nul
set /a link=0
for /f "tokens=2" %%i in ('tasklist /fi "imagename eq Thunder5.exe" /nH 2^>nul^|findstr /i "Thunder5.exe"') do (
set id=
set /a id=%%i
if "!id!"=="" goto :sa
for /f "tokens=4" %%y in ('netstat -anop tcp^|findstr /e /c:"!id!"') do (
if "%%y"=="" goto :eof
if "%%y"=="ESTABLISHED" (set /a link=!link!+1)
)
)
if !link! GEQ 4 (echo.&echo.&echo 迅雷下载中.....) else (echo.&echo.&echo 尝试连接.继续等待...)
:sa
set new=
set /a tm+=3
if not "!link!"=="0" (echo.&echo 当前共!link!个连接 & goto :jj) else (
for /f "delims=" %%h in ('dir "%dir_%\*.td" "%dir_%\*.td.cfg" /a-d /b 2^>nul') do (
if "%%h"=="" (goto :sd)
findstr /x /c:"%%h" c:\temp.txt >nul||set /a new+=1
)
set /a txt=%ge1%-%ge%
if !txt! equ !new! (goto :jj)
)
:sd
shutdown /f /s /c "^-^下载完毕!正在执行关机 "
:un
cls&set /p undown=如果你还未进行下载,请输入n来取消关机,否则不输入:
if /I "%undown:~0,1%"=="n" (shutdown -a &echo 你取消关机,请按任意键退出..&pause>nul) else (goto :un)
Last edited by gool123456 on 2010-5-6 at 21:49 ]
Thanks to everyone's suggestions, the accuracy of the judgment has been further improved.
This P processing is not very useful, just used as a reference here..
The code is written with Thunder 5. If you are not using Thunder 5, please change the name to your downloader's name. It has been tested that other downloaders can also be used, as long as you replace the name of the downloader with the following Thunder5.exe.
Save the following code as "Thunder Shutdown Monitoring.bat":
@echo off&setlocal EnableDelayedExpansion
::Thunder Shutdown Monitoring code by gool123456 @ 2010
::============================
mode con cols=50 lines=10
title Thunder Shutdown Monitoring code by gool123456
set /p dir_=Drag the folder to be monitored in (press Enter for the current folder):
if "%dir_%"=="" set "dir_=%cd%"
set "dir_=%dir_:"=%"
cd.>"c:\temp.txt"
dir "%dir_%" /a-d /b>>"c:\temp.txt"
for /f "delims=:" %%a in ('dir "%dir_%" /a-d /b^|findstr /n .') do (set /a "ge=%%a")
:begin
echo Download not started. Waiting to start...
ping 127.1 -n 3 >nul&cls
:jj
for /f "delims=:" %%b in ('dir "%dir_%" /a-d /b^|findstr /n .') do (set /a "ge1=%%b")
if !ge1! GTR !ge! goto :xiazai
if !ge1! equ !ge! goto :begin
:xiazai
ping 127.1 -n 3 >nul&cls
<nul set/p= Current time : %time% &set/p=Elapsed time: %tm% seconds<nul
set /a link=0
for /f "tokens=2" %%i in ('tasklist /fi "imagename eq Thunder5.exe" /nH 2^>nul^|findstr /i "Thunder5.exe"') do (
set id=
set /a id=%%i
if "!id!"=="" goto :sa
for /f "tokens=4" %%y in ('netstat -anop tcp^|findstr /e /c:"!id!"') do (
if "%%y"=="" goto :eof
if "%%y"=="ESTABLISHED" (set /a link=!link!+1)
)
)
if !link! GEQ 4 (echo.&echo.&echo Thunder is downloading.....) else (echo.&echo.&echo Trying to connect. Continue waiting...)
:sa
set new=
set /a tm+=3
if not "!link!"=="0" (echo.&echo Current total!link! connections & goto :jj) else (
for /f "delims=" %%h in ('dir "%dir_%\*.td" "%dir_%\*.td.cfg" /a-d /b 2^>nul') do (
if "%%h"=="" (goto :sd)
findstr /x /c:"%%h" c:\temp.txt >nul||set /a new+=1
)
set /a txt=%ge1%-%ge%
if !txt! equ !new! (goto :jj)
)
:sd
shutdown /f /s /c "^-^Download completed! Shutdown is being executed "
:un
cls&set /p undown=If you haven't started downloading yet, enter n to cancel the shutdown, otherwise don't enter:
if /I "%undown:~0,1%"=="n" (shutdown -a &echo You canceled the shutdown, press any key to exit..&pause>nul) else (goto :un)
Last edited by gool123456 on 2010-5-6 at 21:49 ]
|

Discuz! 现在时间 |
|
2010-4-24 21:01 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
|
2010-4-24 21:06 |
|
|
exzzz
初级用户
  游手好闲 + 无所事事 ..
积分 194
发帖 167
注册 2007-4-30
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
这个批处理是相当的无聊。。。
你还不如写个更简单实用的,自动监控迅雷下载任务,完成后自动转移到其他目录,避免迅雷上传,影响网速。
This batch processing is quite boring...
You might as well write a simpler and more practical one that automatically monitors Thunder download tasks, and after completion, automatically transfers them to other directories to avoid Thunder uploading and affecting network speed.
|

|
|
2010-4-24 22:39 |
|
|
rs369007
初级用户
 
积分 147
发帖 131
注册 2008-9-22
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
大致看了下,楼主可能对网络协议不是很懂(其实我也不是很懂)
SYN_SENT:是在用connect 函数发起连接
ESTABLISHED:表示一个tcp连接经过三次握手后已经建立完毕,可以开始通信
你的判断的应该先排除迅雷与迅雷服务器的连接,
netstat 显示的tcp状态似乎没有能判断这个端口是否是正在传送数据,建立起tcp连接后程序可以通过某端口“随时”发送数据,状态还是ESTABLISHED,所以不能说tcp状态为ESTABLISHED,就说迅雷在下东西了。
Last edited by rs369007 on 2010-4-24 at 23:26 ]
Roughly looked at it, the original poster may not understand network protocols very well (actually I don't understand either).
SYN_SENT: is when using the connect function to initiate a connection
ESTABLISHED: means that a tcp connection has been established after three-way handshake and can start communication
Your judgment should first rule out the connection between Thunder and the Thunder server.
The tcp state displayed by netstat doesn't seem to be able to judge whether this port is transmitting data. After the tcp connection is established, the program can send data "at any time" through a certain port, and the state is still ESTABLISHED, so it can't be said that the tcp state is ESTABLISHED, it means that Thunder is downloading.
Last edited by rs369007 on 2010-4-24 at 23:26 ]
|

freedom! |
|
2010-4-24 23:16 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by exzzz at 2010-4-24 22:39:
这个批处理是相当的无聊。。。
你还不如写个更简单实用的,自动监控迅雷下载任务,完成后自动转移到其他目录,避免迅雷上传,影响网速。
这个批处理也是有个朋友想通过迅雷下载完毕后,通过批处理或者不用第3方软件当迅雷下完指定任务后可以自动关机。
我在这个功能上加上了一些小功能,其实真正目的是为了下载后能通过它来关机。
而不是真正做个下载器。这也没意思。
你怕上传影响网速,还不如直接KILL了。
Last edited by gool123456 on 2010-4-25 at 14:01 ]
Originally posted by exzzz at 2010-4-24 22:39:
This batch processing is quite boring...
You might as well write a simpler and more practical one that automatically monitors Thunder download tasks and automatically transfers them to other directories after completion to avoid Thunder uploading and affecting internet speed.
This batch processing is also because a friend wanted to automatically shut down the computer when Thunder finishes downloading a specified task through a batch processing or without using third-party software. I added some small functions to this function. In fact, the real purpose is to be able to shut down the computer after downloading.
It's not really to make a downloader. That's not interesting.
If you are afraid that uploading will affect internet speed, it's better to just KILL it directly.
Last edited by gool123456 on 2010-4-25 at 14:01 ]
|

Discuz! 现在时间 |
|
2010-4-25 00:11 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
本身不是有这个功能麽?
Doesn't it originally have this function?
|

S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore |
|
2010-4-25 15:11 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Originally posted by slore at 2010-4-25 15:11:
本身不是有这个功能麽?
是有的,在迅雷的“工具”菜单里。
但用批处理监控也不错。优点是监控是否有连接的,不用等待连接断开请求。
Last edited by gool123456 on 2010-4-25 at 21:44 ]
Originally posted by slore at 2010-4-25 15:11:
Doesn't it have this function itself?
Yes, it's in the "Tools" menu of Thunder.
But monitoring with batch processing is also good. The advantage is that it monitors whether there is a connection without waiting for the connection to be disconnected and requested.
Last edited by gool123456 on 2010-4-25 at 21:44 ]
|

Discuz! 现在时间 |
|
2010-4-25 21:43 |
|
|
exzzz
初级用户
  游手好闲 + 无所事事 ..
积分 194
发帖 167
注册 2007-4-30
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by gool123456 at 2010-4-25 09:43 PM:
是有的,在迅雷的“工具”菜单里。
但用批处理监控也不错。优点是监控是否有连接的,不用等待连接断开请求。
Last edited by gool123456 on 2010-4-25 at 21:44 ]
如楼上某位所言,你没有考虑到连接服务器的情况,连接到服务器之后,也是有连接建立起来的。
此外,我所说的,监控迅雷已下载完成的任务并转移到其他目录,并不是kill就行。
你还得考虑到迅雷有这2个问题:1、下载后并不会自动退出迅雷。2、某个任务下载完成后,还有其他的任务需要下载,不可以kill迅雷,我需要他下载,不要他上传。
Last edited by exzzz on 2010-4-25 at 23:22 ]
Originally posted by gool123456 at 2010-4-25 09:43 PM:
It exists in the "Tools" menu of Thunder.
But monitoring with batch processing is also good. The advantage is that it monitors whether there is a connection, without waiting for the connection to be disconnected.
Last edited by gool123456 on 2010-4-25 at 21:44 ]
As someone mentioned upstairs, you didn't consider the situation of connecting to the server. After connecting to the server, there is also a connection established.
In addition, what I said, monitoring the tasks that Thunder has completed downloading and transferring them to other directories is not just killing.
You also need to consider these two problems of Thunder: 1. Thunder does not automatically exit after downloading. 2. After a certain task is downloaded, there are other tasks that need to be downloaded, and Thunder cannot be killed. I need it to download, not to upload.
Last edited by exzzz on 2010-4-25 at 23:22 ]
|

|
|
2010-4-25 23:20 |
|
|
lena
初级用户
 
积分 154
发帖 67
注册 2007-12-2
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
迅雷不是有下载完毕自动关机吗?lZ这不是多此一举哇?
Thunderstood, the original Chinese sentence is "迅雷不是有下载完毕自动关机吗?lZ这不是多此一举哇?". Translating it: "Doesn't Thunderbolt have an automatic shutdown when the download is complete? LZ, isn't this unnecessary?" But wait, actually "迅雷" is a software name, should be "Thunder", and "lZ" might be a typo for "LZ" which is "楼主" (post owner). So the correct translation should be: "Doesn't Thunder have an automatic shutdown when the download is complete? LZ, isn't this unnecessary?"
|
|
2010-4-26 05:14 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by exzzz at 2010-4-25 23:20:
如楼上某位所言,你没有考虑到连接服务器的情况,连接到服务器之后,也是有连接建立起来的。
此外,我所说的,监控迅雷已下载完成的任 ...
如果是限制迅雷上传的,我在网上搜了下方法有很多。就采用了百科其中一种方法写了一句,可以加上
cd /d "%systemroot%\system32"&&del /q "cid_store.dat"&md "cid_store.dat" & (for %%p in (c: d: e: f: g: h: i: j: k: l:) do (if exist %%p (for /f "delims=" %%f in ('dir /s /a-d /b "%%p\Thunder5.exe"^|findstr /i /c:"\Program\Thunder5.exe"') do (del /q "%%~dpfcid_store.dat" & md "%%~dpfcid_store.dat"))))
Last edited by gool123456 on 2010-4-26 at 18:44 ]
Originally posted by exzzz at 2010-4-25 23:20:
As mentioned by a certain person upstairs, you didn't consider the situation of connecting to the server. After connecting to the server, a connection is also established.
In addition, what I said, monitoring the completed tasks of Thunder...
If it's to limit Thunder's upload, I searched online and there are many methods. I used one method from Baidu Baike to write a sentence, which can be added
cd /d "%systemroot%\system32"&&del /q "cid_store.dat"&md "cid_store.dat" & (for %%p in (c: d: e: f: g: h: i: j: k: l:) do (if exist %%p (for /f "delims=" %%f in ('dir /s /a-d /b "%%p\Thunder5.exe"^|findstr /i /c:"\Program\Thunder5.exe"') do (del /q "%%~dpfcid_store.dat" & md "%%~dpfcid_store.dat"))))
Last edited by gool123456 on 2010-4-26 at 18:44 ]
|

Discuz! 现在时间 |
|
2010-4-26 18:19 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by rs369007 at 2010-4-24 23:16:
大致看了下,楼主可能对网络协议不是很懂(其实我也不是很懂)
SYN_SENT:是在用connect 函数发起连接
ESTABLISHED:表示一个tcp连接经过三次握手后已经 ...
排除服务器连接似乎很难实现。。按严格来代码中的连接是不准确的,因为我不是计算下载的连接,是所有正常连接。
那个“echo迅雷在下载中..”似乎有点在忽悠别人。。。
判断迅雷是否在下载,目前我还没找到窍门。但如果是FTP下载,其实是可以计算文件大小来判断下载速度的。
Originally posted by rs369007 at 2010-4-24 23:16:
Generally speaking, the LZ owner may not be very familiar with network protocols (actually, neither am I)
SYN_SENT: It is when the connect function is used to initiate a connection
ESTABLISHED: It means that a tcp connection has gone through three handshakes and then...
It seems very difficult to exclude server connections. According to strictness, the connection in the code is not accurate, because I am not calculating the downloading connection, but all normal connections.
That "echo Thunder is downloading.." seems a bit misleading others...
Currently, I haven't found a trick to judge whether Thunder is downloading. But if it is FTP downloading, actually, the file size can be calculated to judge the download speed.
|

Discuz! 现在时间 |
|
2010-4-26 18:21 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
|
2010-4-26 18:52 |
|
|
rs369007
初级用户
 
积分 147
发帖 131
注册 2008-9-22
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by gool123456 at 2010-4-26 18:21:
其实是可以计算文件大小来判断下载....
我就是楼主这个思路,监控文件大小。不过觉得这个任有一些难度和问题。
1,用for 扩展读取文件大小 %%~zi ,如果文件没有下完大小还是整个文件完整的大小。
如果监控链接状态,假设能正常监控数据传输状态,但是传输过程中完全有可能会出现链接被意外终止的情况,这必须被考虑(比如网线接口松了、交换机故障等),超过一定时间链接会被终止。所以建议 监控链接状态与检查文件的完整性。
Last edited by rs369007 on 2010-4-26 at 19:15 ]
Originally posted by gool123456 at 2010-4-26 18:21:
Actually, you can calculate the file size to judge the download....
I am following the idea of the original poster, monitoring the file size. However, I feel there are some difficulties and problems with this task.
1. Use the for extension to read the file size %%~zi. If the file is not completely downloaded, the size is still the full size of the entire file.
If monitoring the link status, assuming that the data transmission status can be monitored normally, but during the transmission process, the link may be accidentally terminated completely, which must be considered (such as loose network cable interface, switch failure, etc.). The link will be terminated after a certain period of time. Therefore, it is recommended to monitor the link status and check the integrity of the file.
Last edited by rs369007 on 2010-4-26 at 19:15 ]
|

freedom! |
|
2010-4-26 18:59 |
|
|
rs369007
初级用户
 
积分 147
发帖 131
注册 2008-9-22
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
监控链接刚查了下,在tcp状态下,发起socket主动shutdown的会进入TIME_WAIT状态,如果能先记录一下迅雷刚启动时与所有外部ip的连接(记录下ip和状态吧),间隔<4分钟检查比对一次看看有不有新出现的和其他ip的连接出现TIME_WAIT的。
以前我也写过网络程序用c,如果迅雷主动调用shutdown、或closesocket,应该可以判断迅雷这次和这个“资源服务器”下载对话已经结束了。
I just checked the monitoring link. Under the tcp state, the one that initiates the active shutdown of the socket will enter the TIME_WAIT state. If possible, first record the connections between Thunder just started and all external IPs (record the IP and state), and check and compare every <4 minutes to see if there are new connections with other IPs that enter TIME_WAIT.
I also wrote network programs in C before. If Thunder actively calls shutdown or closesocket, it should be able to judge that Thunder's download dialogue with this "resource server" has ended this time.
|

freedom! |
|
2010-4-26 19:37 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by rs369007 at 2010-4-26 18:59:
我就是楼主这个思路,监控文件大小。不过觉得这个任有一些难度和问题。
1,用for 扩展读取文件大小 %%~zi ,如果文件没有下完大小还是整个文件 ...
嗯 ,是很好的建议。
今天测试过了,确实发现了迅雷有时不在正常连接状态下,依然可以下载. 不知道是不是UDP连接在作怪,还是流量有延缓。。(前提是我限制了下载速度为2K)。我对这方面不是很了解.
Last edited by gool123456 on 2010-4-26 at 20:54 ]
Originally posted by rs369007 at 2010-4-26 18:59:
I am exactly the idea of the original poster, monitoring file size. But I feel there are some difficulties and problems with this task.
1. Use for expansion to read file size %%~zi. If the file is not completely downloaded, the size is still the entire file...
Hmm, it's a very good suggestion.
I tested it today and indeed found that sometimes Thunder doesn't stay in the normal connection state but can still download. I don't know if it's due to UDP connection or delayed traffic. (The premise is that I limited the download speed to 2K). I'm not very familiar with this aspect.
Last edited by gool123456 on 2010-4-26 at 20:54 ]
|

Discuz! 现在时间 |
|
2010-4-26 20:30 |
|