<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 26,  comments - 14,  trackbacks - 0
    殺毒軟件:
    殺毒軟件是每一臺電腦不可少的應用軟件之一,現在我來研究 一下殺毒軟件的整個工作流程吧。。。首先要明確殺毒軟件的目的是什么,怎么樣才能實現這一目的。。。
    殺毒軟件是客戶在通過掃描自己的電腦里的每一個文件,然后與殺毒軟件服務器病毒庫里的病毒相比較,如果你電腦里有和服務器中文件相同的,殺毒軟件就視為是病毒,然后有用戶選擇是否要把掃描出來的文件刪除。。。。下面是我用Java語言來實現這個功能的。。。希望對大家有所感悟。現在說說我的具體實現的步驟吧。



    服務器代碼:

    package server;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.ArrayList;
    import java.util.List;

    import com.dr.bean.Virus;

     


    public class Server {
     


     public static List<Virus> virusList = new ArrayList<Virus>();
     public static void main(String[] args) throws IOException {
      ServerSocket server = null;
      //輸出肯定使用打印流
      PrintStream out = null;
      //服務器肯定也要接收數據
      BufferedReader buf = null;
      //實例化一個服務器的監聽端
      server = new ServerSocket(8888);
      //可以用一種死循環的方式接收內容
      System.out.println("---------服務器已經啟動----------");
      Socket client = null;
      //初始化暗殺名單
      //List<Virus> virusList = getVirusList();
      while(true){
       //不斷接收內容
       client = server.accept();
       //準備好向客戶端輸入內容
       out = new PrintStream(client.getOutputStream());
       //而且客戶端要有輸入給服務器端
       buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
       
       
       //接收客戶端發送過來的內容
       String str = buf.readLine();
       System.out.println("server receive data is:"+str);
       String virus = "";
       if("getVirusList".equals(str)){//組成暗殺協議,返回客戶端
        for(Virus v :virusList){
         virus += v.getName()+":";
        }
        out.println(virus);
       }
       
       //進行收尾工作
       out.flush();
       out.close();
       buf.close();
       client.close();
      }
      
      
     }
     
     public static List<Virus> getVirusList(){
      
      Virus virus = null;
      
      virus = new Virus();
      virus.setName("QQ.exe");
      virusList.add(virus);
      
      virus = new Virus();
      virus.setName("Niu.exe");
      virusList.add(virus);
      
      virus = new Virus();
      virus.setName("Baidu.exe");
      virusList.add(virus);
      
      virus = new Virus();
      virus.setName("Jinshan.exe");
      virusList.add(virus);
      
      return virusList;
     }

     

    }

    執行結果:
     
    客戶端代碼

    package com.dr.client;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.List;

    import com.dr.bean.Virus;


    public class Client {

     private String str;
     private List<Virus> virusList = null;
        public Client(String str){
         this.str = str;
         virusList = new ArrayList<Virus>();
        }
     
     public List<Virus> send() throws UnknownHostException, IOException{
      Socket client = null;
      //接收服務器信息的輸入流
      BufferedReader buf = null;
      //向服務器發送信息的輸出流
      PrintStream out = null;
      //實例化一個套接字
      client = new Socket("localhost",8888);
      //從服務器接收信息
      buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
      //向服務器打印信息
      out = new PrintStream(client.getOutputStream());
      
      
      //打印出去
      out.println(this.str);
      //接收進來QQ.exe:baidu.exe:niu.exe
      String msg = buf.readLine();
      System.out.println(msg);
      String[] msgArray = msg.split(":");
      for(int i=0;i<msgArray.length;i++){
       Virus v = new Virus();
       v.setName(msgArray[i]);
       virusList.add(v);
       System.out.println(msgArray[i]);
      }
      

      buf.close();
      out.flush();
      out.close();
      client.close();
      
      return virusList;
     }
    }

     

    文件掃描過程代碼類:::

    package com.dr.client;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.List;

    import com.dr.bean.Virus;


    public class Client {

     private String str;
     private List<Virus> virusList = null;
        public Client(String str){
         this.str = str;
         virusList = new ArrayList<Virus>();
        }
     
     public List<Virus> send() throws UnknownHostException, IOException{
      Socket client = null;
      //接收服務器信息的輸入流
      BufferedReader buf = null;
      //向服務器發送信息的輸出流
      PrintStream out = null;
      //實例化一個套接字
      client = new Socket("localhost",8888);
      //從服務器接收信息
      buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
      //向服務器打印信息
      out = new PrintStream(client.getOutputStream());
      
      
      //打印出去
      out.println(this.str);
      //接收進來QQ.exe:baidu.exe:niu.exe
      String msg = buf.readLine();
      System.out.println(msg);
      String[] msgArray = msg.split(":");
      for(int i=0;i<msgArray.length;i++){
       Virus v = new Virus();
       v.setName(msgArray[i]);
       virusList.add(v);
       System.out.println(msgArray[i]);
      }
      

      buf.close();
      out.flush();
      out.close();
      client.close();
      
      return virusList;
     }
    }





    KillVirusUI代碼:


    package com.dr.ui;

    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.Font;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.DirectoryDialog;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.ProgressBar;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;

    import com.dr.file.FileList;

    public class KillVirusUI {

     public static String filePath = "";
     public static List<String> virusFilePath = new ArrayList<String>();
     public static void main(String args[]) {
      Display display = new Display();
      final Shell shell = new Shell(display, SWT.SHELL_TRIM);
      shell.setBounds(2, 2, 1200, 600);
      //shell.setMaximized(true);// 全屏顯示
      shell.setText("殺毒軟件簡單版");
      /**
       * 設置執行按鈕
       */
      final Button btnOk = new Button(shell, SWT.PUSH);
      btnOk.setBounds(20, 25, 70, 25);
      btnOk.setText("掃描殺毒");
      final Button btnOk1 = new Button(shell, SWT.PUSH);
      btnOk1.setBounds(120, 25, 70, 25);
      btnOk1.setText("刪除病毒");

       Color color = new Color(Display.getCurrent(), 100, 180, 10);// 聲明顏色對象
       Color color1 = new Color(Display.getCurrent(), 100, 220, 240);// 聲明顏色對象
      final Text text = new Text(shell, SWT.MULTI | SWT.BORDER);
      text.setBounds(10, 270, 1200, 400);
      text.setBackground(color1);
      final Text text1 = new Text(shell, SWT.MULTI | SWT.BORDER);
      text1.setBounds(10, 150, 1200, 50);
      text1.setBackground(color1);
      
      final ProgressBar progressBar = new ProgressBar(shell, SWT.HORIZONTAL);
      GridData data = new GridData();
      data.horizontalSpan = 2;
      data.grabExcessHorizontalSpace = true;
      progressBar.setLayoutData(data);
      progressBar.setMaximum(100);// 設置最大值
      progressBar.setMinimum(0);// 設置最小值
      /**
       * 注冊點擊事件,循環顯示數據
       */
      
      Label labe=new Label(shell,SWT.NULL);
         labe.setBounds(800,25, 120,75); // 設置按鈕位置
         labe.setFont(new Font(display,"宋體",20,SWT.BOLD));
       
       
         labe.setBackground( color);
      labe.setText("    "+"360"+"\n"+"網絡保鏢");
      ;
      btnOk.addSelectionListener(new SelectionAdapter() {//Button監聽事件
       public void widgetSelected(SelectionEvent e) {
        FileList f = new FileList();
        DirectoryDialog dlg = new DirectoryDialog(shell);
        dlg.setText("目錄"); // 設置窗口標題
        dlg.setMessage("請選擇一個目錄:"); // 設置提示文字
        dlg.setFilterPath("/root"); // 設置初始目錄
        String dir = dlg.open(); // 打開對話框并返回一個包含所選目錄路徑的字符串
        
        //File f=new File(dlg.open());
           f.setStr(dir);
        
        if (f != null)
         System.out.println(f); // 比如選擇“我的文檔”,則會打印“D:\My Documents”
        
        
        Thread t = new Thread(f);
        t.setDaemon(true);
        t.start();
        t.yield();
        
        for(int i=0;i<100;i++){
         text.append(filePath+"\n"); 
         progressBar.setBounds(10, 80, 1200, 20);
         progressBar.setSelection(progressBar.getSelection()+1);//顯示一條數據,滾動條進度加1
         try {
          Thread.sleep(1000);
         } catch (InterruptedException e1) {
          e1.printStackTrace();
         }
        }
        
        if(virusFilePath.size()!=0){
         text.setText("");
         for(String str : virusFilePath){
          text1.append("很悲劇:你的電腦里發現病毒:"+str+"\n");
         }
        }
        else{
         text1.setText("恭喜你,沒有發現病毒!");
        }
        t.interrupt();
        
       }
      
      });
      
      
      btnOk1.addSelectionListener(new SelectionAdapter() {//Button監聽事件
       public void widgetSelected(SelectionEvent e) {
        FileList q = new FileList();
        Thread t = new Thread(q);
        t.setDaemon(true);
        t.start();
        for(int i=0;i<100;i++){
         text.append(filePath+"\n");
         progressBar.setBounds(10, 105, 1200, 20);
         progressBar.setSelection(progressBar.getSelection()+1);//顯示一條數據,滾動條進度加1
         try {
          Thread.sleep(100);
         } catch (InterruptedException e1) {
          e1.printStackTrace();
         }
        }
        
        if(virusFilePath.size()!=0){
         text.setText("");
         for(String str : virusFilePath){
          //text1.append("發現病毒:"+str+"\n");
          
             File f1=new File("f.filePath");
          f1.delete();
          text1.append("恭喜你已經成功清理了電腦里的病毒:"+str+"\n");
         }
        }
        else{
         text1.setText("祝賀你不用為電腦安危考慮了!");
        }
       }
       });
      
      
      shell.open();
      while (!shell.isDisposed()) {
       if (!display.readAndDispatch())
        display.sleep();
      }
      display.dispose();
     }
    }

    執行結果:

     
    首先要啟動服務器,殺毒軟件才能夠正常的工作。。。。。。。


    病毒類:

    package com.dr.bean;


    public class Virus{

     private String name;
     public String getName() {
      return name;
     }
     public void setName(String name) {
      this.name = name;
     }
    }


    posted on 2010-11-23 13:43 龍ぜ殘劍 閱讀(2107) 評論(2)  編輯  收藏

    FeedBack:
    # re: 360 殺毒軟件之簡化版
    2010-11-23 16:25 | 龍ぜ殘劍
    過獎了@comanswer
      回復  更多評論
      
    # re: 360 殺毒軟件之簡化版[未登錄]
    2010-11-23 16:32 | abc
    哎,是夠簡化的,就是簡化的CS。殺毒可不是這么簡單的一回事。  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2010年11月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲欧美不卡高清在线| 亚洲日韩欧洲无码av夜夜摸| 亚洲国产最大av| 在线观看免费中文视频| 老司机亚洲精品影院无码 | 亚洲图片在线观看| 国产精品免费高清在线观看| 国产亚洲3p无码一区二区| 成人A毛片免费观看网站| 亚洲国产第一站精品蜜芽| 久久久久久AV无码免费网站| 久久亚洲日韩精品一区二区三区 | 亚洲不卡中文字幕| 久久精品女人天堂AV免费观看| 亚洲人成高清在线播放| 好吊妞在线成人免费| 老牛精品亚洲成av人片| 在线观看亚洲精品国产| 日韩免费人妻AV无码专区蜜桃| 中文字幕亚洲综合久久| 在人线av无码免费高潮喷水| 亚洲码欧美码一区二区三区| 四虎AV永久在线精品免费观看| 一个人看www免费高清字幕| 久久精品国产亚洲一区二区| 97在线视频免费| 亚洲精华国产精华精华液好用 | 一级毛片全部免费播放| 亚洲大尺码专区影院| 免费高清小黄站在线观看| 一区二区在线视频免费观看| 久久亚洲一区二区| 拍拍拍又黄又爽无挡视频免费| 免费精品久久久久久中文字幕| 亚洲成AV人片一区二区| 在线a级毛片免费视频| 国产精品免费久久久久影院| 亚洲国产精品xo在线观看| 亚洲高清无码在线观看| 在免费jizzjizz在线播| 精品国产亚洲一区二区三区在线观看 |