Home Page
  • April 20, 2024, 12:39:46 am *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Official site launch very soon, hurrah!



Post reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

Name:
Email:
Subject:
Message icon:

Attach:
(Clear Attachment)
(more attachments)
Restrictions: 10 per post, maximum total size 8192KB, maximum individual size 5120KB
Note that any files attached will not be displayed until approved by a moderator.
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:
Please stop spamming. Your spam posts are moderated and will never be displayed on the internet. What is eighty-eight minus eighty-six (spell out the answer):
Пожалуйста, прекратите спамить. Ваши спам-сообщения модерируются и никогда не будут отображаться в Интернете. What color is grass.:

shortcuts: hit alt+s to submit/post or alt+p to preview


Topic Summary

Posted by: Dakusan
« on: October 10, 2017, 06:35:19 pm »

Original post for Ping Connectivity Monitor can be found at https://www.castledragmire.com/Posts/Ping_Connectivity_Monitor.
Originally posted on: 10/10/17

The following is a simple bash script to ping a different domain once a second and log the output. By default, it pings #.castledragmire.com, where # is an incrementing number starting from 0.

The script is written for Cygwin (See the PING_COMMAND variable at the top) but is very easily adaptable to Linux.

The log output is: EPOCH_TIMESTAMP DOMAIN PING_OUTPUT



#This uses Window's native ping since the Cygwin ping is sorely lacking in options
#"-n 1"=Only runs once, "-w 3000"=Timeout after 3 seconds
#The grep strings are also directly tailored for Window's native ping
PING_COMMAND=$(
   echo 'C:/Windows/System32/PING.EXE -n 1 -w 3000 $DOMAIN |';
   echo 'grep -iP "^(Request timed out|Reply from|Ping request could not find)"';
)

i=0 #The subdomain counter
STARTTIME=`date +%s.%N` #This holds the timestamp of the end of the previous loop

#Infinite loop
while true
do
   #Get the domain to run. This requires a domain that has a wildcard as a primary subdomain
   DOMAIN="$i.castledragmire.com"

   #Output the time, domain name, and ping output
   echo `date +%s` "$DOMAIN" $(eval $PING_COMMAND)

   #If less than a second has passed, sleep up to 1 second
   ENDTIME=`date +%s.%N`
   SLEEPTIME=$(echo "1 - ($ENDTIME - $STARTTIME)" | bc)
   STARTTIME=$ENDTIME
   if [ $(echo "$SLEEPTIME>0" | bc) -eq 1 ]; then
      sleep $SLEEPTIME
      STARTTIME=$(echo "$STARTTIME + $SLEEPTIME" | bc)
   fi

   #Increment the subdomain counter
   let i+=1
done