国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

掃描整個網段的多線程程序

2019-11-17 06:00:11
字體:
來源:轉載
供稿:網友

  掃描500個ip10秒鐘左右, 一個IP等待0.3秒

java寫的過程編程,供參考:

package steeven;

import java.sql.*;

import java.io.*;

import java.util.*;

import java.text.*;

import javax.servlet.http.*;

public class Ip extends Common implements Runnable{

public String ip; // IP, 用戶名, 主機名

ResultSet list; // 分頁顯示的記錄集

public Ip cur; // 分頁顯示的當前記錄

static public Hashtable ping = new Hashtable(); //ping 后的結果集

static int threadCount = 0; //當前線程的數量, 防止過多線程摧毀電腦

public Ip() {}

public Ip(String ip){

this.ip=ip;

Thread r = new Thread(this);

r.start();

}

public static void Ping(String ip) throws Exception{

//最多30個線程

while(threadCount>30)

Thread.sleep(50);

threadCount +=1;

Ip p = new Ip(ip);

}

public void PingAll() throws Exception{

threadCount =0;

ping = new Hashtable();

while(next()) //next()對所有局域網Ip放到cur

Ping(cur.ip);

//等著所有Ping結束

while(threadCount>0)

Thread.sleep(50);

}

public void run(){

try{

PRocess p= Runtime.getRuntime().exec ("ping "+ip+ " -w 300 -n 1");

InputStreamReader ir = new InputStreamReader(p.getInputStream());

LineNumberReader input = new LineNumberReader (ir);

//讀取結果行

for (int i=1 ; i<7; i++)

input.readLine();

String line= input.readLine();

if (line.length()<17 line.substring(8,17).equals("timed out"))

ping.put(ip,new Boolean(false));

else

ping.put(ip,new Boolean(true));

//線程結束

threadCount -= 1;

}catch (IOException e){}

}

public static void main(String[] args) throws Exception{

Ip ip= new Ip();

ip.PingAll();

java.util.Enumeration key = ping.keys();

String k;

while((k = (String)key.nextElement()) != null)

System.out.println(k+": "+ping.get(k));

}

}

上一篇:Wireless Messaging API

下一篇:線程與Swing

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵宝市| 滕州市| 互助| 清远市| 安西县| 依安县| 梁山县| 庄河市| 宕昌县| 罗山县| 当阳市| 林周县| 汝阳县| 宜君县| 军事| 中西区| 襄汾县| 盐亭县| 本溪市| 麻江县| 元谋县| 温州市| 绥阳县| 宁蒗| 临澧县| 松潘县| 广灵县| 永泰县| 宁远县| 西平县| 穆棱市| 都昌县| 宁武县| 安阳县| 淮北市| 望城县| 于田县| 民勤县| 石首市| 福建省| 武川县|