⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiemian.java

📁 用Java,实现网路中数据的采集
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
//=========================================================
// 网络流量管理系统
// Version:1.0
// Start:  2004-12
// Finish: 2005-01
// Script Written by 李敏 Nanhua University
//=========================================================
// Copyright (C) 2001-2005 5ics.Net. All rights reserved.
// Web: http://www.5ics.net
// Email: leon_520520@hotmail.com
//=========================================================

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.Graphics;          

import java.awt.font.*;
import java.awt.*;
import java.awt.print.*;
import java.awt.Graphics;  
import java.awt.*;

import javax.swing.*;
import javax.swing.table.*;

 class Thewindow extends Frame implements ActionListener
{MenuBar menubar;//菜单条
PopupMenu menu1,menu2,menu3;//菜单项
MenuItem item11,item3,item4,item5,item6,item7,item8,item10,item101,item102,item103,item104,item105,item106,item107,item108,item109;//菜单子项
TextArea ta;
 FileDialog filedialog_load;
Thewindow(String s)
  {super(s);
    setLayout(new GridLayout(1,1));//布局
    setSize(1200,1200);
    setBackground(Color.blue);//窗口背景颜色
    setVisible(true);
     ta=new TextArea("\n\n\n\n\n\t\t\t没有选择",100,200);
    
     add("Center",ta);
    menubar=new MenuBar();//创建菜单条
    menu1=new PopupMenu("文件");
    menu2=new PopupMenu("功能");
    
   menu3=new PopupMenu("图表");
 
   item11=new MenuItem("文本导入数据库");
   
    item3=new MenuItem("保存");
   
    item5=new MenuItem("退出");
    
     item7=new MenuItem("按包长及协议统计");
    item8=new MenuItem("按地址统计");
    item106=new MenuItem("天流量统计图(按包数统计)");
     item107=new MenuItem("天流量统计图(按字节数统计)");
    
    item108=new MenuItem("周流量统计图(按包数统计)");
     item109=new MenuItem("周流量统计图(按字节数统计)");
    
    item10=new MenuItem("第一周统计图");
     item101=new MenuItem("第二周统计图");
      
       item103=new MenuItem("第三周统计图");
        item104=new MenuItem("第四周统计图");
        item102=new MenuItem("周柱状统计图");
   item105=new MenuItem("月统计图");
   
    item5.setActionCommand("退出");
    
  
    menu1.add(item11);
      
 ;
    menu1.addSeparator();//加一条横向分割线,以示区别
    menu1.add(item5);
   
     
    menu2.add(item7);
      menu2.addSeparator();
     menu2.add(item8);
  menu3.add(item106);
      
        menu3.add(item107);
         menu3.add(item108);
      
        menu3.add(item109);
      menu3.add(item10);
      
        menu3.add(item101);
          
            menu3.add(item103);  
              menu3.add(item104);
    menu3.add(item102);
     menu3.add(item105);
    
    item8.addActionListener(this);
     item11.addActionListener(this);
      item7.addActionListener(this);
     item102.addActionListener(this);
      item10.addActionListener(this);
       item101.addActionListener(this);
       item103.addActionListener(this);
      item104.addActionListener(this);
       item105.addActionListener(this);
   item106.addActionListener(this);
       item107.addActionListener(this);
       item108.addActionListener(this);
       item109.addActionListener(this);
    item5.addActionListener(this);
    
    menubar.add(menu1);
    menubar.add(menu2);
    menubar.add(menu3);
   
setMenuBar(menubar);//把菜单条设置好
     filedialog_load=new FileDialog(this,"打开文件对话框",FileDialog.LOAD);
  filedialog_load.setVisible(false);
  filedialog_load.addWindowListener(new WindowAdapter()
  {public void windowClosing(WindowEvent e)
   {filedialog_load.setVisible(false);}
  });
    addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {       setVisible(false);
            	System.exit(0);
            }
        });
        
}
    
public void actionPerformed(ActionEvent e)
{
	if(e.getSource()==item5)
  System.exit(0);
 
  {if(e.getSource()==item11)
		{
			filedialog_load.setVisible(true);
			String s;
			try{
				File file=new File(filedialog_load.getDirectory(),filedialog_load.getFile());
				Runtime ce=Runtime.getRuntime();
				ce.exec(file.toString());
		    	}
			catch(FileNotFoundException e1){}
			catch(IOException e2){}
			
			
		}
  	
  	}
 
	
	
if(e.getSource()==item8)
		{
			FileWin Win=new FileWin();
		Win.pack();
		}
if(e.getSource()==item7)
		{
		FileWin2 Win=new FileWin2();
		Win.pack();
		}	
 if(e.getSource()==item102)
		{
DrawGraph Win=new DrawGraph();
Win.setSize(700, 600);
Win.setTitle("DrawGraph");
Win.setVisible(true);	
		}
if(e.getSource()==item10)	
	{	Huitu mainFrame = new Huitu();
		mainFrame.setSize(700, 600);
    	mainFrame.setBackground(Color.black);
    	mainFrame.setTitle("第一周统计图");
		//mainFrame.setTitle("周流量统计图(按包数统计)");
		mainFrame.setVisible(true);
  }
  if(e.getSource()==item101)	
	{	Huitu1 mainFrame = new Huitu1();
		mainFrame.setSize(700, 600);
		 mainFrame.setBackground(Color.white);//窗口背景颜色
		mainFrame.setTitle("第二周统计图");
		mainFrame.setVisible(true);
  }
  if(e.getSource()==item103)	
	{	Huitu2 mainFrame = new Huitu2();
		mainFrame.setSize(700, 600);
		mainFrame.setBackground(Color.yellow);
		mainFrame.setTitle("第三周统计图");
		mainFrame.setVisible(true);
  }
  if(e.getSource()==item104)	
	{	Huitu3 mainFrame = new Huitu3();
		mainFrame.setSize(700, 600);
		mainFrame.setBackground(Color.orange);
		mainFrame.setTitle("第四周统计图");
		mainFrame.setVisible(true);
  }
if(e.getSource()==item105)
  {Huitu4 mainFrame = new Huitu4();
  mainFrame.setSize(700,600);
  mainFrame.setBackground(Color.black);
  mainFrame.setTitle("月统计图");
  mainFrame.setVisible(true);
  }
if(e.getSource()==item106)
  {Huitu5 mainFrame = new Huitu5();
  mainFrame.setSize(700,600);
  mainFrame.setBackground(Color.black);
  mainFrame.setTitle("天流量统计图(按包数统计)");
  mainFrame.setVisible(true);
  }
if(e.getSource()==item107)
  {Huitu6 mainFrame = new Huitu6();
  mainFrame.setSize(700,600);
  mainFrame.setBackground(Color.black);
  mainFrame.setTitle("天流量统计图(按字节数统计)");
  mainFrame.setVisible(true);
  }
if(e.getSource()==item108)
  {Huitu7 mainFrame = new Huitu7();
  mainFrame.setSize(700,600);
  mainFrame.setBackground(Color.black);
  mainFrame.setTitle("周流量统计图(按包数统计)");
  mainFrame.setVisible(true);
  }
if(e.getSource()==item109)
  {Huitu8 mainFrame = new Huitu8();
  mainFrame.setSize(700,600);
  mainFrame.setBackground(Color.black);
  mainFrame.setTitle("周流量统计图(按字节数统计)");
  mainFrame.setVisible(true);
  }
}


class FileWin extends Frame  implements ActionListener
{
	MenuBar menubar;
    Label label;
    Label label1;
    TextArea ta;
    TextArea tb;

    Menu menu;
    MenuItem item,item1;
    Button btn;
    Button bt;
    Button b;
    Connection con;Statement sql;ResultSet rs;
    
	FileWin()
	{
		super("地址统计窗口");
        setSize(10,10); 
        setVisible(true);
        setLayout(new BorderLayout());
        label=new Label("");
        add(label);
         menubar=new MenuBar();
        menu=new Menu("文件");
        setMenuBar(menubar);
        item=new MenuItem("打印"); 
        item.addActionListener(this);
        item1=new MenuItem("退出") ;
         item1.addActionListener(this);
        menu.add(item);
        menu.add(item1);
        menubar.add(menu);
        ta=new TextArea(40,40); 
          tb=new TextArea(40,40); 
        this.add(ta,BorderLayout.WEST); 
        this.add(tb,BorderLayout.EAST); 
  
        ta.setText("dst_ip结果");
         tb.setText("src_ip结果");
  
        btn=new Button("按dst_IP统计按纽");btn.addActionListener(this);
        bt=new Button("按SRC_IP统计按纽");bt.addActionListener(this); 
         b=new Button("按协议统计按纽"); 
         b.setBounds(new Rectangle(10,10,100,30));
        this.add(btn,BorderLayout.NORTH);
        this.add(bt,BorderLayout.SOUTH);
        
        item1.addActionListener(this);
         addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
            	dispose();
            }
        });
        pack();
        
        
    }
public void actionPerformed(ActionEvent e)
   { if(e.getSource()==item1)
      dispose();
   	  
       if(e.getSource()==btn)
      {
      	 try{
      	 	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      	 }
      	 catch(ClassNotFoundException e4)
      	 {}
      	 try{
      	 	con=DriverManager.getConnection("jdbc:odbc:zuoye","","");
      	 	sql=con.createStatement();
      	    
      	 	rs=sql.executeQuery("SELECT dst_ip AS Expr1,count(*) as bb FROM s6 GROUP BY dst_ip having count(*)>30000 order by bb desc");
      	 	
      	 	while(rs.next())
      	 	{
      	 		String s1=rs.getString(1);
      	 		int i1=rs.getInt(2);
      	 
      	 ta.append("目的IP:"+s1+"访问次数:"+i1+'\n');
      	 	} 
      	 	
      	    con.close();
      	 }	
      	 catch(SQLException e1){}
       }
       
       
       if(e.getSource()==bt)
      {
      	 try{
      	 	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      	 }
      	 catch(ClassNotFoundException e4)
      	 {}
      	 try{
      	 	con=DriverManager.getConnection("jdbc:odbc:zuoye","","");
      	 	sql=con.createStatement();
      	    
      	 	rs=sql.executeQuery("SELECT src_ip AS Expr1,count(*) as bb FROM s6 GROUP BY src_ip having count(*)>32000 order by bb desc");
      	 	
      	 	while(rs.next())
      	 	{
      	 		String s1=rs.getString(1);
      	 		int i1=rs.getInt(2);
      	 	
      	 tb.append("源IP:"+s1+"访问次数:"+i1+'\n');
      	 	} 
      	 	
      	    con.close();
      	 }	
      	 catch(SQLException e1){}
       }
    }	 
}
class FileWin2 extends Frame  implements ActionListener
{
	MenuBar menubar;
    Label label;
     Label label1;
    
    TextArea ta;
     TextArea tb;
    
    Menu menu;
    MenuItem item,item1;
    Button btn;
    Button bt;
    Button b;
    Connection con;Statement sql;ResultSet rs;
    ResultSet rs1;
    ResultSet rs2;
	FileWin2()
	{
		super("包长以及协议统计窗口");
        setSize(10,10); 
        setVisible(true);
        setLayout(new BorderLayout());
        label=new Label("");
        
        add(label);
        
       
        menubar=new MenuBar();
       menu=new Menu("文件");
        setMenuBar(menubar);
        item=new MenuItem("打印"); 
        item.addActionListener(this);
        item1=new MenuItem("退出") ; 
        item1.addActionListener(this);
        menu.add(item);
        menu.add(item1);
        menubar.add(menu);
        ta=new TextArea(40,40); 
          tb=new TextArea(40,40); 
        this.add(ta,BorderLayout.WEST); 
        this.add(tb,BorderLayout.EAST); 
      
        ta.setText("协议统计结果");
         tb.setText("包长统计");
       
        btn=new Button("按协议统计按纽");btn.addActionListener(this);
        bt=new Button("按包长统计按纽");bt.addActionListener(this); 
         b=new Button("按协议统计按纽");
         b.setBounds(new Rectangle(10,10,100,30));
        this.add(btn,BorderLayout.NORTH);
        this.add(bt,BorderLayout.SOUTH);
        
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
            	dispose();
            }
        });
        pack();
    }
public void actionPerformed(ActionEvent e)
   { if(e.getSource()==item1)
   	  dispose();
       if(e.getSource()==btn)
      {
      	 try{
      	 	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      	 }
      	 catch(ClassNotFoundException e4)
      	 {}
      	 try{
      	 	con=DriverManager.getConnection("jdbc:odbc:zuoye","","");
      	 	sql=con.createStatement();
      	    
      	 	rs=sql.executeQuery("SELECT COUNT(protocol) AS Expr1 FROM s6 WHERE (protocol = '6')");
      	 	
      	 	
      	 	while(rs.next())
      	 	{
      	 		
      	 		int i1=rs.getInt(1);
      	 
      	 ta.append('\n'+"TCP个数:"+i1+'\n');
     
      	 	} 
      	 	rs1=sql.executeQuery("SELECT COUNT(protocol) AS Expr1 FROM s6 WHERE (protocol = '17')");
      	 	
      	 	while(rs1.next())
      	 	{
      	 		
      	 		int i2=rs1.getInt(1);
      	 
       ta.append('\n'+"UDP个数:"+i2+'\n');
      	
      	 	} 
      	 	rs2=sql.executeQuery("SELECT COUNT(protocol) AS Expr1 FROM s6 WHERE (protocol <> '17'and protocol<>'6')");
      	 	while(rs2.next())
      	 	{
      	 		
      	 		int i3=rs2.getInt(1);
      	 	
      	 	
       ta.append('\n'+"ICMP个数:"+i3+'\n');
      	
      	 	} 
      	    con.close();
      	 }	
      	 catch(SQLException e1){}
       }
       
       
       if(e.getSource()==bt)
      {
      	 try{
      	 	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      	 }
      	 catch(ClassNotFoundException e4)
      	 {}
      	 try{
      	 	con=DriverManager.getConnection("jdbc:odbc:zuoye","","");
      	 	sql=con.createStatement();
      	    
      	 	rs=sql.executeQuery("SELECT length, COUNT(*) AS COUNT FROM s6   GROUP BY length    ORDER BY COUNT DESC");
      	 	
      	 	while(rs.next())
      	 	{
      	 		String s1=rs.getString(1);
      	 		int i1=rs.getInt(2);
      	 
      	 tb.append('\n'+"包长:"+s1+"           个数:"+i1+'\n');
      	 	} 
      	 	
      	    con.close();
      	 }	
      	 catch(SQLException e1){}
       }
    }	 
}
//周统计图
class DrawGraph extends Frame implements ActionListener{
	MenuBar menubar;
       Menu menu;
      MenuItem item11,item22;
	public DrawGraph() {
		setLayout(new GridLayout(1,1));//布局
       setSize(1200,1200);
       setBackground(Color.white);//窗口背景颜色
      setVisible(true);
		int monlen;
		int tueslen;
		int wedlen;
		int thurlen;
		int frilen;
		int satlen;
		int sunlen;
       System.out.println("Starting DrawGraph...");
	 menubar=new MenuBar();
       menu=new Menu("文件");
      
        item11=new MenuItem("打印"); 
       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -