Port Scanner (Java)

Source: Internet
Author: User

Import java.net .*;
Import java. Io .*;


Public class implements runnable
{
Private inetaddress IPaddress;
Private int port;
Private thread allportthread;

Public IP (string IPaddress, int port)
{
Try
{
This. IPaddress = This. IPaddress. getbyname (IPaddress );
This. Port = port;
}
Catch (exception E)
{
System. Out. println ("the host does not exist .");
}
}

Public void run ()
{

Try
{
Socket testport = new socket (this. IPaddress, this. Port); // if this port cannot been connected, throw a exception.
System. Out. println (this. Port + ": exist"); // If connected, print out.
}
Catch (exception e ){}
}

Public static void main (string [] ARGs)
{
String STR;
STR = "tpoi route 1.0-network host failed/N ";
STR + = "Author: t.t (tpoi: http://www.tpoi.net)/n ";
STR + = "Usage: usage <Options> STR + = "<Options> List:/N ";
STR + = "-Allport: scan the status of all the ports of the specified host/N ";
STR + = "-port % 0: scan the status of the specified ports (% 0) of the specified host/n ";
STR + = "Examples:/N ";
STR + = "Your-Allport www.microsoft.com/N ";
STR + = "Your-port 80 21.64.34.191 ";

If (ARGs. Length = 0)
{
System. Out. println (STR );
}
Else
{
ARGs [0] = ARGs [0]. touppercase (). Trim ();
Char switchargs = ARGs [0]. charat (1 );
Switch (switchargs)
{
Case 'A ':
{
For (INT I = 1; I <= 65535; I ++)
{
Using maindomains = new domains (ARGs [1], I );
If (maindomains. allportthread. activecount ()> 100)
Maindomains. Run ();
Else
{
Mainpipeline. allportthread = new thread (mainpipeline );
Mainusers. allportthread. Start ();
}
}
Break;
}
Case 'p ':
{
Using mainvertex = new vertex (ARGs [2], java. Lang. Integer. parseint (ARGs [1], 10 ));
Try
{
Maindomains. Run ();
}
Catch (exception E)
{
System. Out. println ("parameter error ");
}
Break;
}
Default:
System. Out. println (STR );
}
}
}
}

 

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.