home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) import sys import string import win32ras class ConnectionError(Exception): pass def Connect(rasEntryName, numRetries = 5): for info in win32ras.EnumConnections(): if string.lower(info[1]) == string.lower(rasEntryName): print 'Already connected to', rasEntryName return (0, info[0]) (dial_params, have_pw) = win32ras.GetEntryDialParams(None, rasEntryName) print 'Connecting to', rasEntryName, '...' retryCount = numRetries while retryCount > 0: (rasHandle, errCode) = win32ras.Dial(None, None, dial_params, None) if win32ras.IsHandleValid(rasHandle): bValid = 1 break print 'Retrying...' win32api.Sleep(5000) retryCount = retryCount - 1 if errCode: raise ConnectionError(errCode, win32ras.GetErrorString(errCode)) errCode return (1, rasHandle) def Disconnect(handle): if type(handle) == type(''): for info in win32ras.EnumConnections(): if string.lower(info[1]) == string.lower(handle): handle = info[0] break continue else: raise ConnectionError(0, "Not connected to entry '%s'" % handle) win32ras.HangUp(handle) usage = 'rasutil.py - Utilities for using RAS\n\nUsage:\n rasutil [-r retryCount] [-c rasname] [-d rasname]\n \n -r retryCount - Number of times to retry the RAS connection\n -c rasname - Connect to the phonebook entry specified by rasname\n -d rasname - Disconnect from the phonebook entry specified by rasname\n' def Usage(why): print why print usage sys.exit(1) if __name__ == '__main__': import getopt try: (opts, args) = getopt.getopt(sys.argv[1:], 'r:c:d:') except getopt.error: why = None Usage(why) retries = 5 if len(args) != 0: Usage('Invalid argument') for opt, val in opts: if opt == '-c': Connect(val, retries) if opt == '-d': Disconnect(val) if opt == '-r': retries = int(val) continue