Java multithreaded routines that scan the entire network segment

Source: Internet
Author: User

Scan for 500 IP10 seconds or so, an IP wait 0.3 seconds

Ashamed to say, I think it is written in Java process programming, a little bit for reference only:

Package Steeven
Import java.sql.*;
import java.io.*;
import java.util.*;
Import java.text.*;< br> import javax.servlet.http.*;
public class IP extends Common implements runnable{
public String IP;//IP, username, host name
ResultSet list;//Paging display Recordset
public Ip cur;//paging display current record
static public Hashtable ping = new Hashtable (); result set
static int threa after//ping DCount = 0; The number of current threads, preventing too many threads from destroying the computer
public IP () {}
Public IP (String Ip) {
This.ip=ip
Thread r = new Thread (this);
R.start ();
}
public static void Ping (String IP) throws exception{
//MAX 30 Threads
while (threadcount>30)
Thread.sle EP (50);
ThreadCount +=1;
IP p = new IP (IP);
}
public void Pingall () throws exception{
ThreadCount =0;
Ping = new Hashtable (),
while (Next ())//nex T () Place all LAN IP on cur
ping (cur.ip);
/wait for all Ping to close
while (threadcount>0)
Thread.Sleep;
}
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);
//Read result row
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);
//thread End
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 ());
}
}

1. Using ping is more stupid, but relatively simple

2. If ping succeeds, use nbtstat also can get host name, current username, MAC address ... Everything is in the grip:)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.