使用方法:
1 |
python pingcheck.py <目标> |
比如
1 |
python pingcheck.py 8.8.8.8 |
简单的小脚本…跨平台…分别用了pynotify和pywin32库来执行通知, 因此需要安装相应的库才可以使用.
用ping检查网络通断,并且在通断情况改变时提示用户…
下载地址:
脚本(任意平台): http://movieinfofetch.googlecode.com/files/pingcheck.py
Windows下的已编译版本(需要VC2005运行库): http://movieinfofetch.googlecode.com/files/pingcheck.exe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#!/usr/bin/python import subprocess,platform,sys if len(sys.argv)<2: print "Usage: pingcheck <target>" sys.exit(1) target=sys.argv[1] if platform.system()[0]!="W": arg=['ping','-n',target] import pynotify notify=lambda a,b:pynotify.Notification(a,b).show() else: arg=['ping','-t',target] import win32com.client axWshShell=win32com.client.Dispatch("WScript.Shell") notify=lambda a,b:axWshShell.Popup(b,5,a,0) title="Ping "+target p=subprocess.Popen(args=arg,bufsize=0,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) s='' status=True while p.poll()==None: a=p.stdout.read(1) if a!='\n': s+=a else: print s s=s.strip() if target not in s and s!='': if 'time=' in s and not status: notify(title,"Server is up!") status=True elif 'time=' not in s and status: notify(title,"Server is down!") status=False s='' |
现在很流行这个麽。。Gildor同学先前也写过Windows平台下的HostMonitor来监视主机在线情况
http://blog.csdn.net/fox_click/archive/2009/11/19/4838940.aspx
在HUST不稳定的网络里很有用处的- –
直接用 cmd ping
ImportError: No module named win32com.client
– -.
需要安装pywin32库
几个礼拜前,刚收到 寄来的 Ubuntu 10.04 的光盘、、
恭喜=.=
多少個月沒更新拉
恩,是个问题..
有没有Facebook上自动Poke的脚本……
您自重去…
那就只好手动咯……
=.= ping -a 表示蛋定….
windows用户淡定不能..
另外, 午夜党淡定不能…..