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



          服務(wù)器代碼:

          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;
            //服務(wù)器肯定也要接收數(shù)據(jù)
            BufferedReader buf = null;
            //實(shí)例化一個(gè)服務(wù)器的監(jiān)聽端
            server = new ServerSocket(8888);
            //可以用一種死循環(huán)的方式接收內(nèi)容
            System.out.println("---------服務(wù)器已經(jīng)啟動(dòng)----------");
            Socket client = null;
            //初始化暗殺名單
            //List<Virus> virusList = getVirusList();
            while(true){
             //不斷接收內(nèi)容
             client = server.accept();
             //準(zhǔn)備好向客戶端輸入內(nèi)容
             out = new PrintStream(client.getOutputStream());
             //而且客戶端要有輸入給服務(wù)器端
             buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
             
             
             //接收客戶端發(fā)送過來(lái)的內(nèi)容
             String str = buf.readLine();
             System.out.println("server receive data is:"+str);
             String virus = "";
             if("getVirusList".equals(str)){//組成暗殺協(xié)議,返回客戶端
              for(Virus v :virusList){
               virus += v.getName()+":";
              }
              out.println(virus);
             }
             
             //進(jìn)行收尾工作
             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;
           }

           

          }

          執(zhí)行結(jié)果:
           
          客戶端代碼

          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;
            //接收服務(wù)器信息的輸入流
            BufferedReader buf = null;
            //向服務(wù)器發(fā)送信息的輸出流
            PrintStream out = null;
            //實(shí)例化一個(gè)套接字
            client = new Socket("localhost",8888);
            //從服務(wù)器接收信息
            buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
            //向服務(wù)器打印信息
            out = new PrintStream(client.getOutputStream());
            
            
            //打印出去
            out.println(this.str);
            //接收進(jìn)來(lái)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;
            //接收服務(wù)器信息的輸入流
            BufferedReader buf = null;
            //向服務(wù)器發(fā)送信息的輸出流
            PrintStream out = null;
            //實(shí)例化一個(gè)套接字
            client = new Socket("localhost",8888);
            //從服務(wù)器接收信息
            buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
            //向服務(wù)器打印信息
            out = new PrintStream(client.getOutputStream());
            
            
            //打印出去
            out.println(this.str);
            //接收進(jìn)來(lái)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("殺毒軟件簡(jiǎn)單版");
            /**
             * 設(shè)置執(zhí)行按鈕
             */
            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);// 聲明顏色對(duì)象
             Color color1 = new Color(Display.getCurrent(), 100, 220, 240);// 聲明顏色對(duì)象
            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);// 設(shè)置最大值
            progressBar.setMinimum(0);// 設(shè)置最小值
            /**
             * 注冊(cè)點(diǎn)擊事件,循環(huán)顯示數(shù)據(jù)
             */
            
            Label labe=new Label(shell,SWT.NULL);
               labe.setBounds(800,25, 120,75); // 設(shè)置按鈕位置
               labe.setFont(new Font(display,"宋體",20,SWT.BOLD));
             
             
               labe.setBackground( color);
            labe.setText("    "+"360"+"\n"+"網(wǎng)絡(luò)保鏢");
            ;
            btnOk.addSelectionListener(new SelectionAdapter() {//Button監(jiān)聽事件
             public void widgetSelected(SelectionEvent e) {
              FileList f = new FileList();
              DirectoryDialog dlg = new DirectoryDialog(shell);
              dlg.setText("目錄"); // 設(shè)置窗口標(biāo)題
              dlg.setMessage("請(qǐng)選擇一個(gè)目錄:"); // 設(shè)置提示文字
              dlg.setFilterPath("/root"); // 設(shè)置初始目錄
              String dir = dlg.open(); // 打開對(duì)話框并返回一個(gè)包含所選目錄路徑的字符串
              
              //File f=new File(dlg.open());
                 f.setStr(dir);
              
              if (f != null)
               System.out.println(f); // 比如選擇“我的文檔”,則會(huì)打印“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);//顯示一條數(shù)據(jù),滾動(dòng)條進(jìn)度加1
               try {
                Thread.sleep(1000);
               } catch (InterruptedException e1) {
                e1.printStackTrace();
               }
              }
              
              if(virusFilePath.size()!=0){
               text.setText("");
               for(String str : virusFilePath){
                text1.append("很悲劇:你的電腦里發(fā)現(xiàn)病毒:"+str+"\n");
               }
              }
              else{
               text1.setText("恭喜你,沒有發(fā)現(xiàn)病毒!");
              }
              t.interrupt();
              
             }
            
            });
            
            
            btnOk1.addSelectionListener(new SelectionAdapter() {//Button監(jiān)聽事件
             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);//顯示一條數(shù)據(jù),滾動(dòng)條進(jìn)度加1
               try {
                Thread.sleep(100);
               } catch (InterruptedException e1) {
                e1.printStackTrace();
               }
              }
              
              if(virusFilePath.size()!=0){
               text.setText("");
               for(String str : virusFilePath){
                //text1.append("發(fā)現(xiàn)病毒:"+str+"\n");
                
                   File f1=new File("f.filePath");
                f1.delete();
                text1.append("恭喜你已經(jīng)成功清理了電腦里的病毒:"+str+"\n");
               }
              }
              else{
               text1.setText("祝賀你不用為電腦安危考慮了!");
              }
             }
             });
            
            
            shell.open();
            while (!shell.isDisposed()) {
             if (!display.readAndDispatch())
              display.sleep();
            }
            display.dispose();
           }
          }

          執(zhí)行結(jié)果:

           
          首先要啟動(dòng)服務(wù)器,殺毒軟件才能夠正常的工作。。。。。。。


          病毒類:

          package com.dr.bean;


          public class Virus{

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



          FeedBack:
          # re: 360 殺毒軟件之簡(jiǎn)化版
          # re: 360 殺毒軟件之簡(jiǎn)化版[未登錄]
          2010-11-23 16:32 | abc
          哎,是夠簡(jiǎn)化的,就是簡(jiǎn)化的CS。殺毒可不是這么簡(jiǎn)單的一回事。  回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2010年11月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 吕梁市| 九台市| 黄浦区| 洞口县| 南京市| 永福县| 弥勒县| 内江市| 崇仁县| 寿宁县| 富阳市| 凉城县| 怀柔区| 清远市| 垦利县| 泾川县| 五莲县| 青川县| 长海县| 诸城市| 甘孜| 通化县| 治县。| 阿瓦提县| 平潭县| 通渭县| 东阳市| 余江县| 双牌县| 浦北县| 会理县| 若尔盖县| 思茅市| 绵阳市| 织金县| 宁德市| 昆山市| 宜兰市| 巴塘县| 义乌市| 临夏市|