Browse Source

static fields are new to me ffs

Marius Schwarz 4 years ago
parent
commit
9ce1d9564d
1 changed files with 14 additions and 12 deletions
  1. 14 12
      nmap-to-json.py

+ 14 - 12
nmap-to-json.py

@@ -9,13 +9,15 @@ hosts = []
 
 # Describe the port fields
 class Port:
-    port_number = 0
-    state = ""
-    protocol = ""
-    owner = ""
-    service = ""
-    sunRPCinfo = ""
-    version = ""
+
+    def __init__(self):
+        self.port_number = 0
+        self.state = ""
+        self.protocol = ""
+        self.owner = ""
+        self.service = ""
+        self.sunRPCinfo = ""
+        self.version = ""
 
     def __str__(self):
         return f"Port {self.port_number} - Version: {self.version}"
@@ -42,10 +44,11 @@ class Port:
 
 # Class to represent all the host attributes
 class Host:
-    ip = ""
-    status = ""
-    hostname = ""
-    ports = [] # Array of Port() items
+    def __init__(self):
+        self.ip = ""
+        self.status = ""
+        self.hostname = ""
+        self.ports = [] # Array of Port() items
 
     def merge_ports(self, host):
 
@@ -80,7 +83,6 @@ def parse_line(line):
 
     # Create new Instance
     host = Host()
-    host.ports = [] # needs to get reset
 
     # Split line into different fields
     fields = line.split("\t")