Board logo

标题: Windows使用Ping+将脚本转换为exe应用程序 [打印本页]

作者: admin    时间: 2021-12-19 08:48     标题: Windows使用Ping+将脚本转换为exe应用程序

Windows安装第三方库:(pyinstaller) C:\Users\jacky\Desktop>pip3 install pyinstaller -i http://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com Windows卸载第三方库:(pyinstaller) C:\Users\jacky\Desktop>pip3 uninstall pyinstaller -y Uninstalling pyinstaller-4.9: Successfully uninstalled pyinstaller-4.9 ############ 脚本内容:( Ping_blog.zhuohua.store.py ) #coding=utf-8 import os import datetime,time def func1(): dt = datetime.datetime.now() tt = dt.strftime('%Y%m%d_%H%M%S') Key_t = "\n\n检测时间:" + tt f_name = open(Path_1,'a') #写入(追加)具体检测时间到文件 f_name.write(Key_t) f_name.close() #调用Windows命令的同时,还调用了全局变量 String_1 = "ping " + Key_1 + " -n 10 >> " + Path_1 os.system(String_1) def func_main(func,second): while True: #进程会无限次地自动执行下去 func() time.sleep(second) if __name__ == '__main__': Key_1 = "blog.zhuohua.store" #全局变量 Path_1 = "d:/1.txt" #全局变量 func_main(func1,60) #每隔60秒后执行一次函数func1() ############ 将脚本转换为exe应用程序:(先切换到脚本所在目录) C:\Users\jacky>cd Desktop C:\Users\jacky\Desktop>cd dir1 C:\Users\jacky\Desktop\dir1>pyinstaller.exe -F -w Ping_blog.zhuohua.store.py 命令执行成功: 图片1.png 命令执行成功后,脚本所在目录里会生成一个spec文件,以及文件夹“build”、“dist”: 图片2.png 一个与脚本同名的exe应用程序会生成在文件夹“dist”里面:(双击即可运行) 图片3.png 笺注: 转换为exe应用程序后,就可以在没有安装Python的电脑上运行了,只需要Ping_blog.zhuohua.store.exe一个文件就够; 实验中,使用32位系统、32位的Python软件;制作出来的程序是32位的,可以在其他32位、64位Windows系统中正常使用。 ############ Ping_blog.zhuohua.store.exe运行后,文件d:\1.txt自动记录的数据:(以下只是最后三次的结果) 检测时间:20220226_010928 正在 Ping blog.zhuohua.store [47.75.39.177] 具有 32 字节的数据: 来自 47.75.39.177 的回复: 字节=32 时间=24ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=17ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=17ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=19ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=26ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=18ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=25ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=19ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=24ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=17ms TTL=128 47.75.39.177 的 Ping 统计信息: 数据包: 已发送 = 10,已接收 = 10,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 17ms,最长 = 26ms,平均 = 20ms 检测时间:20220226_011038 正在 Ping blog.zhuohua.store [47.75.39.177] 具有 32 字节的数据: 来自 47.75.39.177 的回复: 字节=32 时间=18ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=21ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=23ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=18ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=20ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=21ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=19ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=20ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=21ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=19ms TTL=128 47.75.39.177 的 Ping 统计信息: 数据包: 已发送 = 10,已接收 = 10,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 18ms,最长 = 23ms,平均 = 20ms 检测时间:20220226_011147 正在 Ping blog.zhuohua.store [47.75.39.177] 具有 32 字节的数据: 来自 47.75.39.177 的回复: 字节=32 时间=18ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=306ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=141ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=21ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=17ms TTL=128 请求超时。 请求超时。 来自 47.75.39.177 的回复: 字节=32 时间=31ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=18ms TTL=128 来自 47.75.39.177 的回复: 字节=32 时间=21ms TTL=128 47.75.39.177 的 Ping 统计信息: 数据包: 已发送 = 10,已接收 = 8,丢失 = 2 (20% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 17ms,最长 = 306ms,平均 = 71ms ############ Win7中查看程序Ping_blog.zhuohua.store.exe的进程:( CMD命令: taskmgr 图片4.png 结束程序Ping_blog.zhuohua.store.exe的进程树:(Win10中选择“结束任务”) 图片5.png 结束程序Ping_blog.zhuohua.store.exe的进程树成功: 图片6.png 相关文章: Windows使用Ping

图片附件: 图片1.png (2022-2-26 20:53, 138.71 KB) / 下载次数 73
http://blog.zhuohua.store/attachment.php?aid=19134&k=3103abb3d8e2cf9cca0d1665d0067ef9&t=1714246513&sid=xC0J9c



图片附件: 图片2.png (2022-2-26 21:00, 79.9 KB) / 下载次数 77
http://blog.zhuohua.store/attachment.php?aid=19135&k=d1ebe28f8d3385376e7f03afa27b694f&t=1714246513&sid=xC0J9c



图片附件: 图片3.png (2022-2-26 21:00, 67.91 KB) / 下载次数 67
http://blog.zhuohua.store/attachment.php?aid=19136&k=e9954c86f871f260b1e70d658d89876f&t=1714246513&sid=xC0J9c



图片附件: 图片4.png (2022-2-26 21:01, 83.81 KB) / 下载次数 70
http://blog.zhuohua.store/attachment.php?aid=19137&k=0b09c8179882630aa751016db377461b&t=1714246513&sid=xC0J9c



图片附件: 图片5.png (2022-2-26 21:02, 30.95 KB) / 下载次数 66
http://blog.zhuohua.store/attachment.php?aid=19138&k=9e44e86ee1e1a4d041ef85b15a51fb92&t=1714246513&sid=xC0J9c



图片附件: 图片6.png (2022-2-26 21:02, 82.23 KB) / 下载次数 66
http://blog.zhuohua.store/attachment.php?aid=19139&k=7d13c85e4ced0b937953d8c1dfb48a18&t=1714246513&sid=xC0J9c






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2