Home Page
  • April 20, 2024, 05:18:22 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: December 23, 2010, 11:32:33 am »

Original post for Ping URL can be found at https://www.castledragmire.com/Posts/Ping_URL.
Originally posted on: 12/23/10

The following is a Python script that automatically pings a requested web address at a given interval. It was made as a quick favor for a friend. Here is the downloadable source code and Windows binary.

The Configuration Options File (PingURL.cfg) contains 2 lines:
  1. The URL to ping (The default pings the GetIP script)
  2. The millisecond interval between pings (Default=600000=10 minutes)


#!python
from sys import stderr
from urllib import urlopen
from time import localtime, strftime, sleep

#Main function
def Main():
   #Open the settings file
   SettingFileName='PingURL.cfg';
   Settings=[] #Blank out settings file variable in case it can't be opened
   try:
       Settings=open(SettingFileName, 'r').readlines()
   except IOError as (errno, strerror):
       stderr.write('Cannot open {0} configuration file: I/O error({1}): {2}\n'.format(SettingFileName, errno, strerror))
       return

   #Confirm valid settings were passed
   if(len(Settings)<2):
       stderr.write('Not enough settings found in settings file\n')
       return
   try:
       IntervalTime=int(Settings[1])
   except:
       stderr.write('Invalid interval time\n')
       return
       
   #Ping the URL indefinitely
   while(True):
       try:
           URLText=urlopen(Settings[0]).read()
       except:
           URLText='READ FAILED'
       print 'URL Pinged At {0}: {1}'.format(strftime('%Y-%m-%d %H:%M:%S', localtime()), URLText)
       sleep(IntervalTime/1000)

#Run the program
Main()