Просмотр исходного кода

fix : enable newNode's source & destination address

master
우인혜 6 лет назад
Родитель
Сommit
668f290e6e

+ 19
- 0
.vscode/tasks.json Просмотреть файл

1
+{
2
+    // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+    // for the documentation about the tasks.json format
4
+    "version": "2.0.0",
5
+    "tasks": [
6
+        {
7
+            "label": "verify",
8
+            "type": "shell",
9
+            "command": "mvn -B verify",
10
+            "group": "build"
11
+        },
12
+        {
13
+            "label": "test",
14
+            "type": "shell",
15
+            "command": "mvn -B test",
16
+            "group": "test"
17
+        }
18
+    ]
19
+}

+ 20
- 10
src/main/java/com/mycompany/app/App.java Просмотреть файл

16
         File file = new File("2016_05_05_05.txt"); // Create file variable
16
         File file = new File("2016_05_05_05.txt"); // Create file variable
17
 
17
 
18
         Vector<String> IP = new Vector<String>(10); // inbound ip
18
         Vector<String> IP = new Vector<String>(10); // inbound ip
19
-        Vector<Node> networkNode = new Vector<Node>();  //  Node vector 정의
19
+        Vector<Node> networkNode = new Vector<Node>();  //  Store Node
20
 
20
 
21
         try {
21
         try {
22
             // Insert file in BufferedReader
22
             // Insert file in BufferedReader
23
             BufferedReader reader = new BufferedReader(new FileReader(file));
23
             BufferedReader reader = new BufferedReader(new FileReader(file));
24
-            // 파일을 한줄씩 읽어 넣기 위한 변수 line
25
             String line = null;
24
             String line = null;
26
 
25
 
27
             // Read and Insert 1 line and Excute if not null
26
             // Read and Insert 1 line and Excute if not null
36
                     jsonObject = (JSONObject) jsonParser.parse(line);
35
                     jsonObject = (JSONObject) jsonParser.parse(line);
37
 
36
 
38
                 } catch (ParseException e) {
37
                 } catch (ParseException e) {
39
-                    // TODO Auto-generated catch block
40
                     e.printStackTrace();
38
                     e.printStackTrace();
41
                 }
39
                 }
42
 
40
 
43
-                //  packet 하나씩 받아서 처리
41
+                //  Handling Packet one and one
44
                 try {
42
                 try {
45
                     Packet newPacket = packet.getClass().newInstance();
43
                     Packet newPacket = packet.getClass().newInstance();
46
                     newPacket.eip = jsonObject.get("eip");
44
                     newPacket.eip = jsonObject.get("eip");
65
                         newDest.setDestIp(newPacket.nip);
63
                         newDest.setDestIp(newPacket.nip);
66
                         newDest.setDestPort(newPacket.nport);
64
                         newDest.setDestPort(newPacket.nport);
67
                         newNode.ip = newSource.getSourceIp();
65
                         newNode.ip = newSource.getSourceIp();
68
-                        //  Insert source & destination address
69
-                        newNode.source.add(newSource);
70
-                        newNode.destination.add(newDest);
66
+                        //  Insert source & destination address -> need edit
67
+                        (newNode.source).addElement(newSource);
68
+                        (newNode.destination).addElement(newDest);
71
                         //  sum packet & byte
69
                         //  sum packet & byte
72
                         newNode.sumPkt(newPacket.out_pkt);
70
                         newNode.sumPkt(newPacket.out_pkt);
73
                         newNode.sumByte(newPacket.out_byte);
71
                         newNode.sumByte(newPacket.out_byte);
74
                         //  Insert newNode
72
                         //  Insert newNode
75
                         networkNode.add(newNode);
73
                         networkNode.add(newNode);
76
                     } catch (InstantiationException e) {
74
                     } catch (InstantiationException e) {
75
+                        e.printStackTrace();
77
 
76
 
78
                     } catch (IllegalAccessException e) {
77
                     } catch (IllegalAccessException e) {
78
+                        e.printStackTrace();
79
 
79
 
80
                     }
80
                     }
81
                 }
81
                 }
82
-                else {
82
+                else if(IP.contains(newPacket.eip)){
83
+                    //  Find Node
84
+                    Node searchNode = findNode(networkNode, newPacket.eip);
85
+
83
 
86
 
84
                 }
87
                 }
85
 
88
 
86
                 } catch (InstantiationException e1) {
89
                 } catch (InstantiationException e1) {
87
-                    // TODO Auto-generated catch block
88
                     e1.printStackTrace();
90
                     e1.printStackTrace();
89
                 } catch (IllegalAccessException e1) {
91
                 } catch (IllegalAccessException e1) {
90
-                    // TODO Auto-generated catch block
91
                     e1.printStackTrace();
92
                     e1.printStackTrace();
92
                 }
93
                 }
93
             }
94
             }
98
             e.printStackTrace();
99
             e.printStackTrace();
99
         }
100
         }
100
     }
101
     }
102
+    public static Node findNode(Vector<Node> nodeVector, Object obj){
103
+        for(int i = 0; i < nodeVector.size(); i++){
104
+            if(nodeVector.elementAt(i).ip.equals((String)obj)){
105
+                Node sNode = nodeVector.elementAt(i);
106
+                return sNode;
107
+            }
108
+        }
109
+        return null;
110
+    }
101
 }
111
 }

+ 4
- 4
src/main/java/com/mycompany/app/Eips.java Просмотреть файл

1
 package com.mycompany.app;
1
 package com.mycompany.app;
2
 class Eips{
2
 class Eips{
3
-    String ip;
4
-    int port;
3
+    String ip = null;
4
+    long port = 0;
5
     String getSourceIp(){
5
     String getSourceIp(){
6
         return ip;
6
         return ip;
7
     }
7
     }
8
-    int getSourcePort(){
8
+    long getSourcePort(){
9
         return port;
9
         return port;
10
     }
10
     }
11
     void setSourceIp(Object obj){
11
     void setSourceIp(Object obj){
12
         ip = (String)obj;
12
         ip = (String)obj;
13
     }
13
     }
14
     void setSourcePort(Object obj){
14
     void setSourcePort(Object obj){
15
-        port = (int)obj;
15
+        port = (long)obj;
16
     }
16
     }
17
 }
17
 }

+ 4
- 4
src/main/java/com/mycompany/app/Nips.java Просмотреть файл

1
 package com.mycompany.app;
1
 package com.mycompany.app;
2
 class Nips{
2
 class Nips{
3
-    String ip;
4
-    int port;
3
+    String ip=null;
4
+    long port=0;
5
     String getDestIp(){
5
     String getDestIp(){
6
         return ip;
6
         return ip;
7
     }
7
     }
8
-    int getDestPort(){
8
+    long getDestPort(){
9
         return port;
9
         return port;
10
     }
10
     }
11
     void setDestIp(Object obj){
11
     void setDestIp(Object obj){
12
         ip = (String)obj;
12
         ip = (String)obj;
13
     }
13
     }
14
     void setDestPort(Object obj){
14
     void setDestPort(Object obj){
15
-        port = (int)obj;
15
+        port = (long)obj;
16
     }
16
     }
17
 }
17
 }

+ 34
- 7
src/main/java/com/mycompany/app/Node.java Просмотреть файл

3
 import java.util.Vector;
3
 import java.util.Vector;
4
 
4
 
5
 class Node {
5
 class Node {
6
-    Vector<Eips> source;
7
-    Vector<Nips> destination; 
8
-    String ip; //  ip
6
+    Vector<Eips> source = new Vector<Eips>();
7
+    Vector<Nips> destination = new Vector<Nips>(); 
8
+    String ip=null; //  ip
9
 
9
 
10
     double vulnerability = 1/30;   //  inbound value
10
     double vulnerability = 1/30;   //  inbound value
11
     double aggression;      //  outbound value
11
     double aggression;      //  outbound value
16
 
16
 
17
     Integer total_port_counts;
17
     Integer total_port_counts;
18
 
18
 
19
-    long sumPkt(Object obj){
20
-        return total_pkt + (long)obj;
19
+    void sumPkt(Object obj){
20
+        total_pkt +=(long)obj;
21
     }
21
     }
22
-    long sumByte(Object obj){
23
-        return total_bytes + (long)obj;
22
+    void sumByte(Object obj){
23
+        total_bytes += (long)obj;
24
     }
24
     }
25
+    long getTotal_pkt(){
26
+        return total_pkt;
27
+    }
28
+    long getTotal_bytes(){
29
+        return total_bytes;
30
+    }
31
+    double getVulnerability(){
32
+        return vulnerability;
33
+    }
34
+    double getAggression(){
35
+        return aggression;
36
+    }
37
+    double getCo_efficient(){
38
+        return co_efficient;
39
+    }
40
+    /*
41
+    void setVulnerability(){
42
+
43
+    }
44
+    void setAggression(){
45
+
46
+    }
47
+    void setCo_efficient(){
48
+
49
+    }
50
+    */
51
+
25
 }
52
 }

Двоичные данные
target/classes/com/mycompany/app/App.class Просмотреть файл


Двоичные данные
target/classes/com/mycompany/app/Eips.class Просмотреть файл


Двоичные данные
target/classes/com/mycompany/app/Nips.class Просмотреть файл


Двоичные данные
target/classes/com/mycompany/app/Node.class Просмотреть файл


Загрузка…
Отмена
Сохранить