关于网段扫描的提问

pzb19841116 2006-06-29 10:21:44
小弟近日作课程设计,用java写一个端口扫描程序,课程要求为:
• 演示:使用端口扫描对一台主机进行扫描,并显示出结果( 一台主机上有哪些端口是打开的 )。对一个网段进行 IP 扫描,显示出结果( 一个网段内有哪些主机是开机的 )。
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
• 友好的用户界面。
其中的对段扫描我不知如何实现,请教各位大哥大姐,给小弟指导一二。
...全文
154 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pzb19841116 2006-06-30
  • 打赏
  • 举报
回复
谢谢火,可是你贴的都是对单个机器进行扫描,这个我已经实现了,只是对网段扫描不知如何下手,google上的代码也不理想,有人能给我讲讲设计思路吗
ansys 2006-06-30
  • 打赏
  • 举报
回复
little06 2006-06-30
  • 打赏
  • 举报
回复
有很多现有的代码可以用

上面的都是我在google上查的
little06 2006-06-30
  • 打赏
  • 举报
回复
怎么样扫描计算机系统本地和远程的端口,监测其是打开还是关闭的在很多应用程序中都要用到,下面是用java实现的简单的端口扫描程序。

Source Code:



--------------------------------------------------------------------------------


/*
* Created on 2005-3-22
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author whandey connect to me: whandey@163.com
*
* TODO To change the template for this generated type comment go to
* 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 the " + 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
}

catch(IOException e)
{
fout.println("The port " + nport + " is closed!");
}

}
fout.close();

}
catch(IOException e){}

}
}
little06 2006-06-30
  • 打赏
  • 举报
回复
import java.net.*;
import java.io.*;

public class lookForPorts {

// locate which of the first 1024 ports seem to be hosting TCP servers
// host is read in from the command line or defaults to localhost

public static void main(String[] args) {

Socket theSocket;
String host = "localhost";

if (args.length > 0)
{ host = args[0]; }

for (int i = 0; i < 1024; i++)
{
try {
theSocket = new Socket(host, i);
System.out.println("There is a server on port " + i + " of " + host);
}
catch (UnknownHostException e)
{ System.err.println(e); break;}
catch (IOException e)
{ // must not be a server on this port
}
}
}
}

81,092

社区成员

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

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