- 帖子
- 2
- 积分
- 16
- 技术
- 1
- 捐助
- 0
- 注册时间
- 2015-11-4
|
5楼
发表于 2015-11-4 15:37
| 只看该作者
复杂点的可以考虑用编程语言,下面是aardio代码实现的多线程PING工具,
从文本中载入IP地址,PING失败界面上IP显示为红色,同时 tracert结果输出到IP同名txt文件。
import win.ui;
/*DSG{{*/
var winform = win.form(cls="ING_FORM";text="PING测试";right=599;bottom=399;border="dialog frame";max=false)
winform.add(
listbox={cls="listbox";left=6;top=9;right=588;bottom=386;bgcolor=16777215;edge=1;items={};ownerDraw=true;z=1}
)
/*}}*/
//设定自绘每行的高度
winform.listbox.onMeasureItem = function(measureItem){
measureItem.itemHeight = 16;
}
//自绘列表项
winform.listbox.onDrawItem = function(drawItem){
var text = winform.listbox.getItemText( drawItem.itemID + 1 )
::SetTextColor(drawItem.hDC,winform.listbox.ipColors[drawItem.itemID + 1] ) ;
:rawText(drawItem.hDC,text,#text,drawItem.rcItem,0x20/*_DT_SINGLELINE*/)
}
winform.show()
//显示PING结果
import thread.command;
winform.listbox.ipColors = {};
thread.command().ping = function(ip,reply){
if( reply ){
winform.listbox.add(ip)
winform.listbox.ipColors[winform.listbox.count] = 0xF00
}
else {
winform.listbox.add(ip + " tracert...")
winform.listbox.ipColors[winform.listbox.count] = 0x0f0
}
}
//创建PING线程
import thread.works;
var work = thread.works( 2,
function( ip ) {
import icmp.ping;
import thread.command;
import process.popen;
var ping = icmp.ping();
for(i=1;4;1){
if( ping.perform(ip) ){
thread.command.post("ping",ip, string.format( "Reply from %s: bytes=%d time=%dms TTL=%d"
, ping.ip , #ping.requestData , ping.echoReply.roundTripTime , ping.echoReply.options.ttl ) )
return;
}
sleep(10)
}
thread.command.post("ping",ip );
var prcs = process.popen(,"tracert",ip);
var file = io.open("/" + ip + ".txt","a+b");
for( all,out,err in prcs.each() ){
file.write( out,err );
file.flush();
}
file.close();
prcs.close();
}
);
//添加PING任务
work.push("bbs.aau.cn")
work.push("www.baidu.com")
//如果需要从文本载入IP地址,这样写
if( io.exist("\ip.txt") ){
for ip in io.lines("\ip.txt") {
work.push(ip);
}
}
work.waitClose();
winform.msgbox("后台线程任务已全部完成");
win.loopMessage(); |
-
1
评分人数
-
|