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();
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |