Beispiel #1
0
def winConnect(server):
	name = servers[server]["dsp"]
	address = servers[server]["srv"]
	username = servers[server]["usr"]
	password = util.getPassword(server)

	hdl, retcode = win32ras.Dial (None, None, (name, address, "", username, password, ""), None)
Beispiel #2
0
def Connect(rasEntryName, numRetries=5):
    """Make a connection to the specified RAS entry.
	
	Returns a tuple of (bool, handle) on success.
	- bool is 1 if a new connection was established, or 0 is a connection already existed.
	- handle is a RAS HANDLE that can be passed to Disconnect() to end the connection.
	
	Raises a ConnectionError if the connection could not be established.
	"""
    assert numRetries > 0
    for info in win32ras.EnumConnections():
        if info[1].lower() == rasEntryName.lower():
            print "Already connected to", rasEntryName
            return 0, info[0]

    dial_params, have_pw = win32ras.GetEntryDialParams(None, rasEntryName)
    if not have_pw:
        print "Error: The password is not saved for this connection"
        print "Please connect manually selecting the 'save password' option and try again"
        sys.exit(1)

    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))
    return 1, rasHandle
Beispiel #3
0
def Connect(entryName, bUseCallback):
    if bUseCallback:
        theCallback = Callback
        win32event.ResetEvent(callbackEvent)
    else:
        theCallback = None
    #       in order to *use* the username/password of a particular dun entry, one must
    #       explicitly get those params under win95....
    try:
        dp, b = win32ras.GetEntryDialParams( None, entryName )
    except:
        print("Couldn't find DUN entry: %s" % entryName)
    else:
        hras, rc = win32ras.Dial(None, None, (entryName, "", "", dp[ 3 ], dp[ 4 ], ""),theCallback)
    #       hras, rc = win32ras.Dial(None, None, (entryName, ),theCallback)
    #       print hras, rc
        if not bUseCallback and rc != 0:
            print("Could not dial the RAS connection:", win32ras.GetErrorString(rc))
            hras = HangUp( hras )
        #       don't wait here if there's no need to....
        elif bUseCallback and win32event.WaitForSingleObject(callbackEvent, 60000)!=win32event.WAIT_OBJECT_0:
            print("Gave up waiting for the process to complete!")
            #       sdk docs state one must explcitly hangup, even if there's an error....
            try:
                cs = win32ras.GetConnectStatus( hras )
            except:
                #       on error, attempt a hang up anyway....
                hras = HangUp( hras )
            else:
                if int( cs[ 0 ] ) == win32ras.RASCS_Disconnected:
                    hras = HangUp( hras )
    return hras, rc
Beispiel #4
0
 def _connect():
     try:
         self.save_user(username, passwd, savepass)
         win32ras.SetEntryDialParams(
             RASFILE, ("pyras", "", "", username, passwd, ""), savepass)
         self.session = win32ras.Dial(
             None, RASFILE, ("pyras", "", "", username, passwd, ""),
             None)
     except:
         pass
Beispiel #5
0
    def change_ip(self):
        while True:
            if self.dirty is True:
                self.ip_lock.acquire_write()
                if self.pid is not None:
                    win32ras.HangUp(self.pid)
                    time.sleep(3)
                self.pid, ret = win32ras.Dial(
                    None, None, ('vpn', self.address, "", self.username,
                                 self.password, ""), None)
                print self.pid, ret
                # if ret==0:
                # QtGui.QMessageBox.information(self, u"连接", u'连接vpn')
                # else
                #     QtGui.QMessageBox.information(self, u"连接", u'连接vpn错误')
                self.dirty = False
                self.ip_lock.release_write()

            time.sleep(1)
Beispiel #6
0
import win32ras

try:
    hdl, retcode = win32ras.Dial(None, None,
                                 (vpn_name, ip, "", username, password, ""),
                                 None)
except:
    print 'error'
Beispiel #7
0
def test(rasName="_ Divert Off"):
    return win32ras.Dial(None, None, (rasName, ), TestCallback)
Beispiel #8
0
def Connect(dialname, account, passwd):
    dial_params = (dialname, '', '', account, passwd, '')
    return win32ras.Dial(None, None, dial_params, None)
Beispiel #9
0
    def connect(self):

        pid, ret = win32ras.Dial(None, None, (vpn_name, ip_address, "", username, password, ""), None)
 def _connect():
     return win32ras.Dial(None, None,
                          (settings.VPN_NAME, "", "", "", "", ""), None)
Beispiel #11
0
 def connect(self, account, password, dialname='Netkeeper'):
     dial_params = (dialname, '', '', account, password, '')
     logger.info(str(dial_params))
     return win32ras.Dial(None, None, dial_params, None)
Beispiel #12
0
 def connect_pppoe(self, dialname, account, passwd):
     dial_params = (dialname, '', '', account, passwd, '')
     return win32ras.Dial(None, None, dial_params, None)