2.socket-testing whether the local port is being monitored by the server

Source: Internet
Author: User

Importjava.io.IOException;ImportJava.net.Socket;Importjava.net.UnknownHostException;/*** @name *@authorWujianxiong * @date 2016-5-19*/ Public classPortscanner {/*** @name@paramargs *@authorWujianxiong * @date 2016-5-19*/     Public Static voidMain (string[] args) {//TODO auto-generated Method StubString host = "127.0.0.1"; if(args.length>0) Host= Args[0];    Portscanner.scan (host); }        /*** Scan Port * @name@paramHost *@authorWujianxiong * @date 2016-5-19*/     Public Static voidScan (String host) {Socket socket=NULL; //Scan Port         for(intport=1;port<1024;port++){            Try{Socket=NewSocket (host, Port); System.out.println ("Successful connection to local port:" +port); } Catch(unknownhostexception e) {System.out.println ("Unknown error!" "); } Catch(IOException e) {System.out.println ("Connection port:" +port+ "Failed! "); } finally{                Try {                    if(socket!=NULL) Socket.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }            }        }    }}

2.socket-testing whether the local port is being monitored by the server

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.