我给你写了一个简单的小程序,你可以参考一下,检测端口是1-1024,你可以自己修改一下,其实就是用socket....
/**
* Created by IntelliJ IDEA.
* User: fengzhizi
* Date: 2005-4-5
* Time: 23:02:43
* To change this template use Options | File Templates.
*/
import java.net.*;
import java.io.*;
public class LowPortScanner {
public static void main(String[] args)
{
String host="localhost";
if (args.length>0)
{
host=args[0];
}
for (int i=1;i<1024;i++)
{
try
{
Socket s=new Socket(host,i);
System.out.println("There is a server on port "+i+"of "+host);
}
catch (UnknownHostException e)
{
System.err.println(e);
}
catch (IOException e)
{
}
}
}
}
|