China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 09:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Shut down after Thunder download View 1,949 Replies 14
Original Poster Posted 2010-04-24 21:01 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
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 ]
Floor 2 Posted 2010-04-24 21:06 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
= = Forgot to change the uploaded file to the forum name. Hehe.
Floor 3 Posted 2010-04-24 22:39 ·  中国 广东 深圳 电信
初级用户
★★
游手好闲 + 无所事事 ..
Credits 194
Posts 167
Joined 2007-04-30 09:43
19-year member
UID 87022
Gender Male
Status Offline
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.
Floor 4 Posted 2010-04-24 23:16 ·  中国 四川 攀枝花 电信
初级用户
★★
Credits 147
Posts 131
Joined 2008-09-22 23:54
17-year member
UID 126352
Gender Male
Status Offline
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!
Floor 5 Posted 2010-04-25 00:11 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
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 ]
Floor 6 Posted 2010-04-25 15:11 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Doesn't it originally have this function?
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 7 Posted 2010-04-25 21:43 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
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 ]
Floor 8 Posted 2010-04-25 23:20 ·  中国 广东 深圳 电信
初级用户
★★
游手好闲 + 无所事事 ..
Credits 194
Posts 167
Joined 2007-04-30 09:43
19-year member
UID 87022
Gender Male
Status Offline
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 ]
Floor 9 Posted 2010-04-26 05:14 ·  中国 四川 移动
初级用户
★★
Credits 154
Posts 67
Joined 2007-12-02 16:45
18-year member
UID 104465
Gender Male
Status Offline
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?"
Floor 10 Posted 2010-04-26 18:19 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
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 ]
Floor 11 Posted 2010-04-26 18:21 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
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.
Floor 12 Posted 2010-04-26 18:52 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
Floor 13 Posted 2010-04-26 18:59 ·  中国 四川 攀枝花 电信
初级用户
★★
Credits 147
Posts 131
Joined 2008-09-22 23:54
17-year member
UID 126352
Gender Male
Status Offline
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!
Floor 14 Posted 2010-04-26 19:37 ·  中国 四川 攀枝花 电信
初级用户
★★
Credits 147
Posts 131
Joined 2008-09-22 23:54
17-year member
UID 126352
Gender Male
Status Offline
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!
Floor 15 Posted 2010-04-26 20:30 ·  中国 广东 广州 电信
初级用户
★★
Credits 89
Posts 76
Joined 2009-12-13 13:41
16-year member
UID 156499
Gender Male
Status Offline
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 ]
Forum Jump: