Computer/network device status monitoring script

Source: Internet
Author: User
Tags eol net send

In the past, I wrote a monitoring script to check the IP addresses in an IP list every 10 seconds by using the ping command. If the IP addresses in an IP list cannot be accessed, send messages via the messenger message and use beep to send alarms. Run the script.

Rem main. bat
@ Echo off
For/F "EOL =; tokens = 1, 2 * delims =" % I in (IP. txt) Do call: checkip % I % j 0
Echo --------------------------------------------------------------
Echo ---- the first round of check is complete. If no alarm is reported, all IP addresses can be pinged ----
Echo ---- if an abnormal IP address exists, run the ping command to verify the correctness of the check ----
Echo ---- perform cyclic check now and check an IP address every other MS ----
Echo --------------------------------------------------------------
: Begin
For/F "EOL =; tokens = 1, 2 * delims =" % I in (IP. txt) Do call: checkip % I % J 10000
Goto begin

: Checkip

@ Echo off
Ping % 1-N 1 | find "TTL ="> NUL
If not errorlevel 1 echo % 1 (% 2) Status OK at % time %
If not errorlevel 1 goto next
Ping % 1-N 1-W 3000 | find "TTL ="> NUL
If % errorlevel % = 1 call: Send % 1% 2 else echo % 1 (% 2) Status OK at % time %
: Next
Sleep % 3
Goto end

: Send
@ Echo off
Echo % 1 (% 2): Status error at % time % :::::
For/F "EOL =;" % I in (user. txt) Do net send % I "error pinging % 1 (% 2)."> NUL
Beep 1500 500
Beep 500 500
Beep 1500 500
Beep 500 500
Goto end

: End

;Ip.txt, key IP address, one IP address per line. You can enter a name after the equal sign.
192.168.0.1 = group Gateway
192.168.0.123 = test

When the computer name or IP address detects that the network is disconnected, send a message to the user in the text.
Computername
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.