Skip to content

Instantly share code, notes, and snippets.

@maplpro
Created September 20, 2010 10:16
Show Gist options
  • Save maplpro/587697 to your computer and use it in GitHub Desktop.
Save maplpro/587697 to your computer and use it in GitHub Desktop.
ping site by URL from IronPython
#pinger
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-u", "--url", dest="url", help="url to ping" )
parser.add_option("-l", "--log", dest="log", help="log file for pinging this URL" )
options, args = parser.parse_args()
from ping_core import ping
import logging
logging.basicConfig(filename=options.log,level=logging.DEBUG, format = "%(asctime)s - %(levelname)s - %(message)s" )
while True:
ping( options.url )
import time
import random
next = 60 * 30 * random.random()
logging.info( "Next run in %s minutes" % int( next / 60 ) )
time.sleep( next )
def ping(url):
import logging
try:
import System
from System.Net import CredentialCache
from System.Net import WebClient
client = WebClient()
client.Credentials = CredentialCache.DefaultCredentials
res = client.DownloadString( url )
logging.info( url )
except SystemError, ex:
logging.error( ex )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment