| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2575 人关注过本帖
标题:自己写的局域网端口扫描程序
只看楼主 加入收藏
lw8484654
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-12-1
收藏
 问题点数:0 回复次数:2 
自己写的局域网端口扫描程序

这是我自己写的端口扫描程序,不过有2点失误的地方,第一只能扫描自己的端口,如果是另一个IP,却扫描不出来,我发帖子问了,都没人回答.
第二,扫描的速度特别慢,所以最好从自己的IP开始扫描,而且有的端口第一次扫描出现,第二次没有出现,不知道为什么,希望有人解答.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class SuperScaner extends JFrame
{
public static JTextField sjtf1,sjtf2,sjtf3,sjtf4,ejtf1,ejtf2,ejtf3,ejtf4,threadjtf;
public static JLabel sjl1,sjl2,sjl3,jl4,jl,ejl1,ejl2,ejl3,threadjl,areajl,resultjl;
public static JTextArea jta;
public JPanel jp1,jp2,jp3,jp4,jp;
public JScrollPane jsp;
public static JButton Sbutton,jb2;

public SuperScaner()
{
Container c=getContentPane();

sjtf1=new JTextField(4);sjtf2=new JTextField(4);sjtf3=new JTextField(4);sjtf4=new JTextField(4);
ejtf1=new JTextField(4);ejtf2=new JTextField(4);ejtf3=new JTextField(4);ejtf4=new JTextField(4);
threadjtf=new JTextField(7);

jl=new JLabel(" IP地址:");sjl1=new JLabel(".");sjl2=new JLabel(".");sjl3=new JLabel(".");
jl4=new JLabel("~");threadjl=new JLabel("线程数(1~100):");
areajl=new JLabel("扫描结果:");
ejl1=new JLabel(".");ejl2=new JLabel(".");ejl3=new JLabel(".");resultjl=new JLabel();
resultjl.setLayout(new FlowLayout(FlowLayout.LEFT));

jta=new JTextArea(15,65);
jsp=new JScrollPane(jta);

Sbutton=new JButton("确定");
jb2=new JButton("取消");

jp1=new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.LEFT));
jp2=new JPanel();
jp2.setLayout(new FlowLayout(FlowLayout.LEFT));
jp3=new JPanel();
jp3.setLayout(new BorderLayout());
jp4=new JPanel();
jp4.setLayout(new FlowLayout(FlowLayout.RIGHT));

jp1.add(jl);jp1.add(sjtf1);jp1.add(sjl1);jp1.add(sjtf2);jp1.add(sjl2);jp1.add(sjtf3);jp1.add(sjl3);jp1.add(sjtf4);
jp1.add(jl4);jp1.add(ejtf1);jp1.add(ejl1);jp1.add(ejtf2);jp1.add(ejl2);jp1.add(ejtf3);jp1.add(ejl3);jp1.add(ejtf4);
jp1.add(threadjl);jp1.add(threadjtf);

jp2.add(areajl);jp2.add(jsp);
jp3.add(resultjl,BorderLayout.CENTER);jp4.add(Sbutton);jp4.add(jb2);
jp3.add(jp4,BorderLayout.EAST);

c.add(jp1,BorderLayout.NORTH);
c.add(jp2,BorderLayout.CENTER);
c.add(jp3,BorderLayout.SOUTH);
setSize(740,400);
setResizable(false);
jta.setEditable(false);
setLocation(400,300);
show();

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Sbutton.addActionListener(new Sbutton());
}
public static void main(String args[])
{
new SuperScaner();
}
};
class ThreadScaner implements Runnable
{
public static InetAddress address;
public static int min,max;
private int i;
Object obj = new Object();
public Sbutton s;
public ThreadScaner(Sbutton s)
{
this.s=s;
}

public void run()
{
Socket theTCPsocket;
//SuperScaner.jta.append(address.getHostName()+" , "+address.getHostAddress()+"\n");
for(i=1;i<2000;i++)
{
SuperScaner.resultjl.setText("扫描状态:正在扫描 "+ i +" 端口"+"\n");
try
{
theTCPsocket=new Socket(address,i);
theTCPsocket.close();
SuperScaner.jta.append(" "+i);
switch(i)
{
case 21:
SuperScaner.jta.append("(FTP)");
break;
case 23:
SuperScaner.jta.append("(TELNET)");
break;
case 25:
SuperScaner.jta.append("(SMTP)");
break;
case 80:
SuperScaner.jta.append("(HTTP)");
break;
case 110:
SuperScaner.jta.append("(POP3)");
break;
case 135:
SuperScaner.jta.append("(Remote Procedure Call服务)");
break;
case 139:
SuperScaner.jta.append("(netBIOS)");
break;
case 2000:
SuperScaner.jta.append("(木马默认端口)");
break;
case 3389:
SuperScaner.jta.append("(Win2000 远程登陆端口)");
break;
case 4000:
SuperScaner.jta.append("(OICQ)");
break;
case 6667:
SuperScaner.jta.append("(IRC)");
break;
}
SuperScaner.jta.append("\n");
}
catch (Exception e)
{
}
}
if(i==2000){SuperScaner.jta.append("扫描完成\n");SuperScaner.resultjl.setText(ThreadScaner.address.getHostName()+"扫描状态:完成!\n");Sbutton.is4++;s.caclu();}
}
};
class Sbutton implements ActionListener
{
public static int is1,is2,is3,is4,ie1,ie2,ie3,ie4,threadnum;
ThreadScaner ts=new ThreadScaner(this);
public int i;
byte b[]=new byte[4];
public void actionPerformed(ActionEvent e)
{
if(SuperScaner.sjtf1.getText().length()!=0&&SuperScaner.sjtf2.getText().length()!=0&&SuperScaner.sjtf3.getText().length()!=0&&SuperScaner.sjtf4.getText().length()!=0)
{
is1=Integer.parseInt(SuperScaner.sjtf1.getText());is2=Integer.parseInt(SuperScaner.sjtf2.getText());is3=Integer.parseInt(SuperScaner.sjtf3.getText());is4=Integer.parseInt(SuperScaner.sjtf4.getText());
ie1=Integer.parseInt(SuperScaner.ejtf1.getText());ie2=Integer.parseInt(SuperScaner.ejtf2.getText());ie3=Integer.parseInt(SuperScaner.ejtf3.getText());ie4=Integer.parseInt(SuperScaner.ejtf4.getText());
threadnum=Integer.parseInt(SuperScaner.threadjtf.getText());

if(is1>=0 && is1<=255&&is2>=0&&is2<=255&&is3>=0&&is3<=255&&is4>=0&&is4<=255)
{
if(is1==ie1&&is2==ie2&&is3==ie3&&is4<ie4)
{
ThreadScaner.min=is4;ThreadScaner.max=ie4;
}
}
else JOptionPane.showMessageDialog(null,"数值超出范围","错误提示",JOptionPane.ERROR_MESSAGE);


SuperScaner.jta.setText("");

caclu();
}
else JOptionPane.showMessageDialog(null,"没有输入数据","错误提示",JOptionPane.ERROR_MESSAGE);
}
public void caclu()
{
int count=0;
try
{
if(is4<=ie4){System.out.println(""+is4);
b[0]=(byte)is1;b[1]=(byte)is2;b[2]=(byte)is3;b[3]=(byte)is4;
ThreadScaner.address=InetAddress.getByAddress(b);
SuperScaner.jta.append(ThreadScaner.address.getHostName()+" , "+ThreadScaner.address.getHostAddress()+"\n");
if(ThreadScaner.address.getHostName().equals(ThreadScaner.address.getHostAddress())){SuperScaner.jta.append("这个IP可能没人用!\n");is4++;caclu();}
else{
SuperScaner.jta.append("正在扫描 "+ThreadScaner.address.getHostName()+" 请稍等\n");
SuperScaner.jta.append("开放端口: \n");
while(count<threadnum){new Thread(ts).start();count++;}}
}
else {SuperScaner.jta.append("扫描完成!\n");SuperScaner.resultjl.setText("扫描状态:完成!");}
}
catch (Exception ex)
{
ex.getMessage();
}
}
};

搜索更多相关主题的帖子: 局域网 端口 import 扫描 
2006-09-02 09:31
ukyo502
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-11-10
收藏
得分:0 

我复制过去试了一下,扫描效果不错,赞一个!!!

2006-09-02 10:15
lw8484654
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-12-1
收藏
得分:0 
先别赞了,上面的两个问题该怎么解决呢?
2006-09-02 12:33
快速回复:自己写的局域网端口扫描程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024427 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved