def hangup(self, ensoapi, entryName): try: conn = (i for i in win32ras.EnumConnections() if i[1] == entryName).next() win32ras.HangUp(conn[0]) except: print "Couldn't hangup: %s" % entryName
def HangUp(hras): # trap potential, irrelevant errors from win32ras.... try: win32ras.HangUp(hras) except: print("Tried to hang up gracefully on error, but didn't work....") return None
def disconnect(self): if self.handle is None: return try: win32ras.HangUp(self.handle[0]) finally: self.handle = None
def Disconnect(handle): if type(handle) == type(''): # have they passed a connection name? for info in win32ras.EnumConnections(): if info[1].lower() == handle.lower(): handle = info[0] break else: raise ConnectionError(0, "Not connected to entry '%s'" % handle) win32ras.HangUp(handle)
def Disconnect(rasEntry): # Need to find the entry name = rasEntry.lower() for hcon, entryName, devName, devType in win32ras.EnumConnections(): if entryName.lower() == name: win32ras.HangUp(hcon) print("Disconnected from", rasEntry) break else: print("Could not find an open connection to", entryName)
def HangUpConnection( phonebook_entry ): connlist = win32ras.EnumConnections() #[(655360, 'Office PPTP', 'VPN', 'RASPPTPM')] for conninfo in connlist: if conninfo[1] == phonebook_entry: hrasconn = conninfo[0] win32ras.HangUp( hrasconn ) break else: print 'Not connected.' #print "RAS connection '%s' not found" % phonebook_entry sys.exit(1)
def _disconnect_ras(self): """ 断开连接 """ if self.ckp_task: self.ckp_task.stop() conns = win32ras.EnumConnections() if conns: for conn in conns: try: win32ras.HangUp(conn[0]) except: pass self.session = None
def Disconnect(handle): if handle != None: try: win32ras.HangUp(handle) print "Disconnection success!" return "success" except: print "Disconnection failed, wait for 5 seconds and try again..." time.sleep(5) Disconnect() else: print "Can't find the process!" return
def disconnect(self): flag = self.get_conn() if len(flag) == 1: handle = flag[0][0] dialname = str(flag[0][1]) try: win32ras.HangUp(handle) self.saveData(False, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) logger.info("连接" + dialname + "已断开!") return True except Exception as e: logger.info(dialname + "断开连接失败!" + str(e.message)) # disconnect() else: logger.info("错误的进程号或当前无连接!")
def Disconnect(handle): if handle != None: try: win32ras.HangUp(handle) #防止程序执行过快,导致拨号失败 time.sleep(3) print("Disconnection success!") return "success" except: print("Disconnection failed, wait for 5 seconds and try again...") time.sleep(5) Disconnect() else: print("Can't find the process!") return
def disconnect_pppoe(self, handle): self.print_log("正在断开宽带!") self.pppoeStatusLbl.setText("正在断开") if handle is not None: try: win32ras.HangUp(handle) self.print_log("宽带断开成功!") self.pppoeStatusLbl.setText("断开成功") return "success" except Exception as e: self.print_log("宽带断开失败,3秒后重试") self.pppoeStatusLbl.setText("断开失败") sleep(3) return self.disconnect_pppoe(handle) else: self.print_log("宽带断开异常") self.pppoeStatusLbl.setText("断开失败") return "fail"
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)
import win32ras vpn_name='vpn' ip_address="zzzh.8866.org" username="******" password="******" class PPTPDial: def __init__(self,ip_address,username,password): self.ip_address=ip_address self.username=self.username self.password=self.password def connect(self): pid, ret = win32ras.Dial(None, None, (vpn_name, ip_address, "", username, password, ""), None) print pid,ret re=win32ras.HangUp(pid) print re