当前位置: 首页 > news >正文

python 操作asdl

#!/usr/bin/env python
# -*- 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 = '宽带连接' #just a name
account = '057992811002'
passwd = '875645'
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(handle)
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)

#get my ipaddress anf disconnect broadband connection.
def main():
data = Check_for_Broadband()
#if exist running broadband connection, disconnected it.
if data != None:
for p in data:
ShowIpAddress(p[0])
if(Disconnect(p[0]) == "success"):
print("%s has been disconnected." % p[1])
time.sleep(0.05)
DialBroadband()
else:
pid, res = DialBroadband()
ShowIpAddress(pid)
return "finsh test"

 

转载于:https://www.cnblogs.com/simadongyang/p/8971255.html

相关文章:

  • 美国国防部推出微型RFID芯片,助力电子零件防伪
  • 常见错误及细小知识点锦集
  • 物联网之父:中国将引领物联网技术实现飞跃
  • React v16.3 版本新生命周期函数浅析及升级方案
  • 连接无处不在——2016年中国国际信息通信展带你叩响未来世界的大门
  • 二、Java面向对象(8)_继承思想——继承关系
  • 行业领袖支招网络安全:如何走出“黑暗时代”?
  • 《程序设计与数据结构》第八周学习总结
  • 报告显示:95.9%的手机网民认为自己曾遇到过信息安全事件
  • 《黑客大曝光:移动应用安全揭秘及防护措施》一2.1 基础移动网络功能
  • JS基础之数据类型、对象、原型、原型链、继承
  • 大数据时代用技术力量缓解春运难题
  • 第0次作业 4班卢炳武
  • 如何有效地管理测试用例
  • 【多线程】将大批量数据插入多张表,怎么知道多张表都插成功了
  • [译] React v16.8: 含有Hooks的版本
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • Brief introduction of how to 'Call, Apply and Bind'
  • CentOS7 安装JDK
  • extract-text-webpack-plugin用法
  • iOS编译提示和导航提示
  • Java|序列化异常StreamCorruptedException的解决方法
  • java8-模拟hadoop
  • Js基础——数据类型之Null和Undefined
  • LeetCode29.两数相除 JavaScript
  • Python_网络编程
  • Redis字符串类型内部编码剖析
  • 从0实现一个tiny react(三)生命周期
  • 基于 Ueditor 的现代化编辑器 Neditor 1.5.4 发布
  • 前端每日实战:61# 视频演示如何用纯 CSS 创作一只咖啡壶
  • 如何借助 NoSQL 提高 JPA 应用性能
  • 入门级的git使用指北
  • 提升用户体验的利器——使用Vue-Occupy实现占位效果
  • 阿里云重庆大学大数据训练营落地分享
  • ​LeetCode解法汇总2182. 构造限制重复的字符串
  • #HarmonyOS:Web组件的使用
  • #NOIP 2014# day.1 T3 飞扬的小鸟 bird
  • ${factoryList }后面有空格不影响
  • (done) 两个矩阵 “相似” 是什么意思?
  • (react踩过的坑)Antd Select(设置了labelInValue)在FormItem中initialValue的问题
  • (Redis使用系列) Springboot 使用redis实现接口幂等性拦截 十一
  • (SpringBoot)第二章:Spring创建和使用
  • (阿里巴巴 dubbo,有数据库,可执行 )dubbo zookeeper spring demo
  • (附源码)node.js知识分享网站 毕业设计 202038
  • (六)c52学习之旅-独立按键
  • (五)大数据实战——使用模板虚拟机实现hadoop集群虚拟机克隆及网络相关配置
  • (一)Linux+Windows下安装ffmpeg
  • (原創) 如何安裝Linux版本的Quartus II? (SOC) (Quartus II) (Linux) (RedHat) (VirtualBox)
  • (转)Oracle存储过程编写经验和优化措施
  • .describe() python_Python-Win32com-Excel
  • .net core 6 集成和使用 mongodb
  • .NET Framework .NET Core与 .NET 的区别
  • .set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
  • .ui文件相关