日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python拨号_python 拨号代码(win10 系统亲测有效)

發布時間:2023/12/20 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python拨号_python 拨号代码(win10 系统亲测有效) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# -*- coding: utf-8 -*-

import win32ras

import time,os

def Connect(dialname, account, passwd):

dial_params = (dialname, '', '', account, passwd, '')

return win32ras.Dial(None, None, dial_params, None)

def DialBroadband():

dialname = u'寬帶連接' #just a name

account = u'059291294332'

passwd = u'189133'

try:

#handle is a pid, for disconnect or showipadrress, if connect success return 0.

#account is the username that your ISP supposed, passwd is the password.

handle, result = Connect(dialname, account, passwd)

if result == 0:

print "Connection success!"

return handle, result

else:

print "Connection failed, wait for 5 seconds and try again..."

time.sleep(5)

DialBroadband()

except:

print "Can't finish this connection, please check out."

return

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 Check_for_Broadband():

connections = []

connections = win32ras.EnumConnections()

if(len(connections) == 0):

print "The system is not running any broadband connection."

return

else:

print "The system is running %d broadband connection." % len(connections)

return connections

def ShowIpAddress(handle):

print win32ras.GetConnectStatus(handle)

data = os.popen("ipconfig","r").readlines()

have_ppp = 0

ip_str = None

for line in data:

if line.find("寬帶連接")>=0:

have_ppp = 1

#if your system language is English, you should write like this:

#if have_ppp and line.strip().startswith("IP Address"):

#in othewords, replace the "IPv4 地址" to "IP Address"

if have_ppp and line.strip().startswith("IPv4 地址"):

ip_str = line.split(":")[1].strip()

have_ppp = 0

print ip_str

def main():

data = Check_for_Broadband()

if data != None:

for p in data:

ShowIpAddress(p[0])

if(Disconnect(p[0]) == "success"):

print "%s has been disconnected." % p[1]

time.sleep(3)

else:

pid, res = DialBroadband()

ShowIpAddress(pid)

time.sleep(3)

# Disconnect(pid)

return "finsh test"

test = main()

print test

總結

以上是生活随笔為你收集整理的python拨号_python 拨号代码(win10 系统亲测有效)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。