hub1314 发表于 2022-5-12 17:00:00

局域网IP在线批量检测工具AliveIP_V1.0和弹窗报警插件

<i class="pstatus"> 本帖最后由 hub1314 于 2022-5-12 17:17 编辑 </i><br />
<br />
<font face="微软雅黑">最近公司做了一个FMCS(厂务自控管理系统)项目,在建设运维期间经学有设备通讯不上,但是又没有好的方式检测设备是否是人为故障还是网线物理故障。在wincc上好像也不容易做设备的掉线检测,于是答应同事自己给他们做一个设备是否在局域网内在线存活的工具。可以当做一个小工具,也可以作为Wincc开发调用的外部插件来使用。当时有400多台设备,检测一遍用了不到20s。下面具体介绍一下这个软件,也把它分享出来,希望做工控方面的朋友有机会用到。</font><br />
<font face="微软雅黑">链接:https://cloud.189.cn/t/va6nUv3aEbM3(访问码:nrb1)<br />
下载压缩文件解压后如下:<br />
</font>
<ignore_js_op>



<div class="tip tip_4 aimg_tip" id="aimg_2521514_menu" style="position: absolute; display: none" disautofocus="true">
<div class="xs0">
<p><strong>image.png</strong> <em class="xg1">(30.94 KB, 下载次数: 0)</em></p>
<p>
<a href="https://www.52pojie.cn/forum.php?mod=attachment&aid=MjUyMTUxNHw3ZTFmMjQ0YXwxNjUyODIwOTY5fDB8MTYzNTIxOQ%3D%3D&nothumb=yes" target="_blank">下载附件</a>

</p>

<p class="xg1 y">2022-5-12 17:09 上传</p>

</div>
<div class="tip_horn"></div>
</div>

</ignore_js_op>
<br />
<br />
<font face="微软雅黑">里面有说明文件</font><br />
<br />
具体操作步骤:<br />
检测功能<br />
一、先从其它地方复制\输入要检测的IP到文档“待检测IP.txt”然后保存。<br />

<ignore_js_op>



<div class="tip tip_4 aimg_tip" id="aimg_2521516_menu" style="position: absolute; display: none" disautofocus="true">
<div class="xs0">
<p><strong>image.png</strong> <em class="xg1">(17.55 KB, 下载次数: 0)</em></p>
<p>
<a href="https://www.52pojie.cn/forum.php?mod=attachment&aid=MjUyMTUxNnw2NGM1NzAyYnwxNjUyODIwOTY5fDB8MTYzNTIxOQ%3D%3D&nothumb=yes" target="_blank">下载附件</a>

</p>

<p class="xg1 y">2022-5-12 17:10 上传</p>

</div>
<div class="tip_horn"></div>
</div>

</ignore_js_op>
<br />
<br />
二、双击AliveIP_V1.0.exe可执行软件,运行软件。会有控制台弹出检测IP的过程,然后在当前文件夹下生成一个&quot;掉线IP.txt&quot;文档。目前我测试的只有192.168.1.2是在线的,其它的都不在这个局域网内。<br />

<ignore_js_op>



<div class="tip tip_4 aimg_tip" id="aimg_2521517_menu" style="position: absolute; display: none" disautofocus="true">
<div class="xs0">
<p><strong>image.png</strong> <em class="xg1">(16.5 KB, 下载次数: 0)</em></p>
<p>
<a href="https://www.52pojie.cn/forum.php?mod=attachment&aid=MjUyMTUxN3wzZmY1YzI5NnwxNjUyODIwOTY5fDB8MTYzNTIxOQ%3D%3D&nothumb=yes" target="_blank">下载附件</a>

</p>

<p class="xg1 y">2022-5-12 17:11 上传</p>

</div>
<div class="tip_horn"></div>
</div>

</ignore_js_op>
<br />
<br />
<br />
<br />
报警功能<br />
三、如果想在电脑或者Wincc上循环启动报警,可参考结合另外一个软件弹窗报警插件。(思路一:用电脑计划任务程序周期运行这两个软件。思路2:在Wincc中用全局脚本周期调用这两个软件)<br />
<br />
四、通过双击ReadLinesCountAndNotice.exe软件,运行报警弹窗程序,可手动报警查看效果。<br />
<br />
<br />
最后奉上源码,python3开发<br />
AliveIP_V1.0.exe 如下==》<br />
import threading<br />
import subprocess<br />
import time<br />
import os<br />
from queue import Queue<br />
start_time=time.time()<br />
#删除指定文件<br />
if os.path.exists('掉线IP.txt'):<br />
&nbsp; &nbsp; os.remove('掉线IP.txt')<br />
#定义工作线程<br />
WORD_THREAD=50<br />
#定义IP列表<br />
IPs=[]<br />
#将需要ping 的ip加入队列<br />
IP_QUEUE = Queue()<br />
# for i in range(1,5):<br />
#&nbsp; &nbsp;&nbsp;&nbsp;IP_QUEUE.put('192.168.1.'+str(i))<br />
# for j in range(1,255):<br />
#&nbsp; &nbsp;&nbsp;&nbsp;IP_QUEUE.put('192.168.2.'+str(j))<br />
<br />
# file1= open('待检测IP.txt','r',encoding='utf-8') #打开要去掉空行的文件<br />
# file2 =open('待检测IP2.txt','w',encoding='utf-8') #生成没有空行的文件<br />
# for line in file1.readlines():<br />
#&nbsp; &nbsp;&nbsp;&nbsp;if line == '\n':<br />
#&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;line=line.strip('\n')<br />
#&nbsp; &nbsp;&nbsp;&nbsp;file2.write(line)<br />
# file1.close()<br />
# file2.close()<br />
<br />
f=open('待检测IP.txt',encoding='utf-8')<br />
lines=f.readlines()<br />
for line in lines:<br />
&nbsp; &nbsp; if line.isspace():<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;continue<br />
&nbsp; &nbsp; else:<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;line=line.replace(&quot;\n&quot;,&quot;&quot;)<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#line =line.replace(&quot;\t&quot;,&quot;&quot;)<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IPs.append(line)<br />
for x in IPs:<br />
&nbsp; &nbsp; #print(x)<br />
&nbsp; &nbsp; IP_QUEUE.put(x)<br />
# with open ('待检测IP.txt') as file:<br />
#&nbsp; &nbsp;&nbsp;&nbsp;for myline in file.readlines():<br />
#&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if myline.isspace:<br />
#&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; continue<br />
#&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else:<br />
<br />
#&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; print(myline)<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#print(myline,end='') #end=&quot;&quot;<br />
#定义一个执行ping 的函数<br />
def ping_ip():<br />
&nbsp; &nbsp; while not IP_QUEUE.empty():<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ip=IP_QUEUE.get()<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;res =subprocess.call('ping -n 1 -w 5 %s' %ip,stdout=subprocess.PIPE) #linux系统将'gn'替换成'-c'<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#运行结果 <br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;print(ip,True if res ==0 else False)<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if res !=0 :<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;with open('掉线IP.txt','a') as f:<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; f.write(ip+'\n')#进行换行输入f.write(ip+'\n')<br />
if __name__ == '__main__':<br />
&nbsp; &nbsp; threads=[]&nbsp; &nbsp;<br />
&nbsp; &nbsp; for i in range(WORD_THREAD):<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;thread=threading.Thread(target=ping_ip)#绑定方法<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;thread.start()<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#time.sleep(0.1)<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;threads.append(thread)<br />
&nbsp; &nbsp; for thread in threads:<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;thread.join()<br />
&nbsp; &nbsp; print('程序运行耗时:%s' %(time.time()-start_time))<br />
-----------------------------------------------<br />
ReadLinesCountAndNotice.exe 如下==》<br />
import win32api,win32con<br />
count = len(open('掉线IP.txt','rU').readlines())<br />
print(count)<br />
if count&gt;=1:<br />
&nbsp; &nbsp; win32api.MessageBox(0,'现已发现掉线设备总数:%s(台),请注意结合&quot;掉线IP.txt&quot;文本信息,安排检查现场!' %count,&quot;提醒&quot;,win32con.MB_YESNOCANCEL)<br />
<br />
总结:小伙伴们可以自己结合实际情况选用,在吾爱论坛成长了很多,终于能不做伸手党,为大家做点事了!<img src="https://www.52pojie.org/static/image/smiley/default/40.gif" smilieid="919" border="0" alt="" /><img src="https://www.52pojie.org/static/image/smiley/default/40.gif" smilieid="919" border="0" alt="" />2022/5/12<br />
<br />
补充:在windows计划任务中执行弹窗,因为我这个弹窗要确认,所以不能在这里面启动。建议做自控的话在WinCC(其它上位机软件)中当作插件来使用。<br />
<br />
<br />
<font face="微软雅黑"><br />
</font>

六小福2288 发表于 2022-5-14 23:14:00

文件呢。前两天收藏起来今天休息想认真看看然后下载,然后就出现楼上所说的的。下面呢。。。。。楼主不要没有下面哦

as040014 发表于 2022-5-13 08:34:00

这个还是挺实用的,我参考一下

tanhaibigg 发表于 2022-5-13 08:46:00

这个用得上,收藏一个。多谢分享。

tintin981 发表于 2022-5-13 09:10:00

谢谢分享,看着就是非常实用的小工具呀。

ybxdmq 发表于 2022-5-13 10:22:00

谢谢楼主分享局域网IP在线批量检测工具AliveIP_V1.0和弹窗报警插件,辛苦了。

吴书醉 发表于 2022-5-13 10:37:00

大佬源码都放出来了,威武

gweig 发表于 2022-5-13 10:39:00

谢谢分享,看着就是非常实用的小工具呀。

yuechaomax 发表于 2022-5-13 11:04:00

查IP无忧,可以用上了。

2737735600 发表于 2022-5-13 11:26:00

学习中......
页: [1] 2
查看完整版本: 局域网IP在线批量检测工具AliveIP_V1.0和弹窗报警插件