Created
September 20, 2010 10:16
-
-
Save maplpro/587697 to your computer and use it in GitHub Desktop.
ping site by URL from IronPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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