多线程ping ip地址
//pingIPimport wsock.tcp.client;
import console;
import thread.worksEx;
import win;
import icmp.ping;
//table1维转2维
var convertTo2DArray = function(arr, rows, columns){
var result = {}
var index = 1
for (i = 1;rows;1) {
result = {}
for (j = 1;columns;1){
result = arr
index = index + 1
}
}
return result
}
var ipTable = {};
for(i=1;255;1){
ipTable = "192.168.1."++i;
}
var ipList = convertTo2DArray(ipTable,26,10)
//创建任务列表
var works = thread.worksEx(#ipList, function(ipAddr) {
//io.open()
import console
import win;
import icmp.ping;
var ping = icmp.ping()
for (i = 1; #ipAddr; 1) {
ping.perform(ipAddr)
var bool = ping.echoReply.status
//win.delay(1000)
//thread.delay(1000)
if (bool == 0) {
console.log(tostring(time()), ipAddr, "成功--YES")
}
else {
//console.log(tostring(time()), ipAddr, "失败")
}
}
return "成功";
});
for(i=1;#ipList;1){
works.push(ipList) //添加任务1
}
works.waitClose() //等待所有任务完成
console.pause(true);
页:
[1]