Program | port scan how to scan the local and remote port of computer system, monitor whether it is turned on or off in many applications, the following is a simple port scanner implemented in Java.
/*
* Created on 2005-3-22
*
* TODO to change the template of this generated file go
* Window-preferences-java-code Style-code Templates
*/
/**
* @author Whandey Connect to Me:whandey@163.com
*
* TODO to change the template of this generated type comment go
* Window-preferences-java-code Style-code Templates
*/
Import java.io.*;
Import java.net.*;
Import java.util.*;
public class Socketport {
public static void Main (string[] args) {
String IP = "159.162.39.27";
string hostname = new string ();
try{//get the target IP address and hostname
InetAddress address = inetaddress.getbyname (IP);
SYSTEM.OUT.PRINTLN (address);
hostname = Address.gethostname ();
SYSTEM.OUT.PRINTLN (hostname);
}
catch (Unknownhostexception e)
{
System.out.println ("Could not find" + IP);
}
Try
{//creat the output file
PrintWriter fout = new PrintWriter (New FileWriter ("PortInf.txt"));
FOUT.PRINTLN ("Information of the Port on" + hostname + "computer");
Fout.println ();
Do ports scan
for (int nport = 25;nport < 30;++nport)
{
Try
{
Socket s = new socket (hostname,nport);
FOUT.PRINTLN ("The port" + Nport + "is open!");
Fout.println ("Connected to" + s.getinetaddress () + ' on port ' + s.getport () + "from port" + s.getlocalport () + "of" + S.getlocaladdress ());
Print the connected socket information
}
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.