如何用java对端口进行扫描?

kingcalcn 2004-03-28 04:22:34
我想用java做个端口扫描器,来检测连接到本机的连接的进程信息。并且希望能够对它的数据包的内容进行分析。现在碰到的问题是:
1、如何实现端口扫描?
2、用java的net包而不使用winsock编程能实现以上功能吗?

热切希望各位高手能给小弟指点。
我的邮箱是:kingcal@126.com
...全文
290 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingcalcn 2004-03-29
  • 打赏
  • 举报
回复
谢谢各位高手!
尤其是shyi,使我知道了如何做一个端口扫描器。
不过还有一个问题还没解决:如何检测连接到本机的连接的进程信息?
升烟 2004-03-28
  • 打赏
  • 举报
回复
使用Runtime.exec("netstat -an",null,null)然后捕捉返回信息
应该也可以行的通(我没试过)
runki 2004-03-28
  • 打赏
  • 举报
回复
关注 顶!!!!
学习
mbl 2004-03-28
  • 打赏
  • 举报
回复
mark
shyi 2004-03-28
  • 打赏
  • 举报
回复
我给你一个端口扫描的JAVA源程序。不过不是我写的。
import java.net.*;
import java.io.*;
public class Scanner implements Runnable
{
private InetAddress IPAddress;
private int Port;
private Thread allportThread;
public Scanner(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 Scanner 1.0 - Network Host Scanner\n";
str += "Author: T.T (TPoI:http://www.tpoi.net)\n\n";
str += "Usage: Scanner <options> <Hostname>\n\n";
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\n";
str += "Examples:\n";
str += " Scanner -allport www.microsoft.com\n";
str += " Scanner -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++)
{
Scanner mainScanner = new Scanner(args[1],i);
if(mainScanner.allportThread.activeCount()>100)
mainScanner.run();
else
{
mainScanner.allportThread = new Thread(mainScanner);
mainScanner.allportThread.start();
}
}
break;
}
case 'P':
{
Scanner mainScanner = new Scanner(args[2],java.lang.Integer.parseInt(args[1],10));
try
{
mainScanner.run();
}
catch(Exception e)
{
System.out.println("parameter error");
}
break;
}
default:
System.out.println(str);
}
}
}
}
小弟是个刚开始念degree的学生,属于新手中的新手,如果有什么比较弱智的地方,请原谅
很想与高人交朋友 msn: zhuo_chang@hotmail.com
QQ:367271
CoolAbu 2004-03-28
  • 打赏
  • 举报
回复
1、用java.net中的socket类,循环的对机器的所有端口进行连接或发送包,然后分析返回的端口响应,就可以实现端口扫描了。


2、用java.net包中的socket类就可以实现上面的功能了。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧