How to realize Network Patrol script with batch processing
This article is about how to use batch processing to implement the network inspection script. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Check.bat content (script content may be typesetting problems can not be directly copied and pasted to run, can be modified):
The code is as follows:
@ echo off
Rem checklist.csv field is: IP, name, description, TCP application port, UDP application port
In rem checklist.csv, please use @, replace, and do not use () for content description
Set e_file=error.log
Set e_count=0
For / f "skip=1 tokens=1,2,3,4,5* delims=,"% I in (checklist.csv) do call: docheck% I @% j @% k @% l @% m
Call: report
Goto: eof
: docheck
Set ip=%1
Set name=%2
Set name=%name:@=%
Set comment=%3
Set comment=%comment:@=%
Set tcp=%4
Set tcp=%tcp:@=%
Set udp=%5
Set udp=%udp:@=%
Ping% ip%-n 3-w 300 > nul 2 > & 1
If NOT% ERRORLEVEL%==0 (echo% time%% ip% [% name%,%comment%] ping error > >% eBay file% & set / an e_count=%e_count%+1) else call: portcheck
Call: report
Goto: eof
: portcheck
If not -% tcp%==- for / f "tokens=1,2,3,4,5,6,7,8,9,10* delims=-"% I in ("% tcp%") do call: tcpcheck% I% j% k% l% m% n% o% p% Q
If not -% udp%==- for / f "tokens=1,2,3,4,5,6,7,8,9,10* delims=-"% I in ("% udp%") do call: udpcheck% I% j% k% l% m% n% o% p% Q
Goto: eof
: tcpcheck
If not -% 1 benchmark-call: tcpquery% 1
If not -% 2clients-call: tcpquery% 2
If not -% 3 thanks-call: tcpquery% 3
If not -% 4clients-call: tcpquery% 4
If not -% 5clients-call: tcpquery% 5
If not -% 6 thanks-call: tcpquery% 6
If not -% 7clients-call: tcpquery% 7
If not -% 8clients-call: tcpquery% 8
If not -% 9 thanks-call: tcpquery% 9
Goto: eof
: udpcheck
If not -% 1 benchmark-call: udpquery% 1
If not -% 2clients-call: udpquery% 2
If not -% 3 thanks-call: udpquery% 3
If not -% 4clients-call: udpquery% 4
If not -% 5clients-call: udpquery% 5
If not -% 6 thanks-call: udpquery% 6
If not -% 7clients-call: udpquery% 7
If not -% 8clients-call: udpquery% 8
If not -% 9 thanks-call: udpquery% 9
Goto: eof
: tcpquery
Portqry-n% ip%-e% 1-p tcp | | (echo% time%% ip% [% name%,%comment%] tcp port% 1 query error > >% eigenfile% & set / an e_count=%e_count%+1)
Goto: eof
: udpquery
Portqry-n% ip%-e% 1-p udp | | (echo% time%% ip% [% name%,%comment%] udp port% 1 query error > >% eigenfile% & set / an e_count=%e_count%+1)
Goto: eof
: report
Echo% eBay count%
Rem do whatever you want. Such as send error.log by mail
Goto: eof
Sample checklist.csv:
IP, name, description, TCP App Port, UDP App Port'to add @ between two commas, description cannot be parenthesized (), replace it with []
192.168.0.1 @
192.168.0.3 @
192.168.0.9 FTPSERVERGER FTP Server, 135-445-21
192.168.0.10 language TESTSERVERMagol 135-445-21 language 53
Thank you for reading! This is the end of the article on "how to use batch processing to achieve network inspection script". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!