summaryrefslogtreecommitdiff
path: root/netforge.py
diff options
context:
space:
mode:
authorgigagamerchaddhruv-spec <gigagamerchaddhruv@gmail.com>2026-05-02 20:54:10 +0530
committerGitHub <noreply@github.com>2026-05-02 20:54:10 +0530
commitcc8bb2b4e2434f3a09243e7259d239b831d03eca (patch)
tree69b5157687fa1048e205b5649442f5a9dddae25f /netforge.py
parent07b486ed1458401735f389506870bf1cae760af9 (diff)
Refactor netforge.py for improved scanning and UI
Diffstat (limited to 'netforge.py')
-rw-r--r--netforge.py111
1 files changed, 29 insertions, 82 deletions
diff --git a/netforge.py b/netforge.py
index a23387c..4f85369 100644
--- a/netforge.py
+++ b/netforge.py
@@ -1,109 +1,60 @@
-import socket
-import ipaddress
-import threading
-import time
import tkinter as tk
from tkinter import ttk
+import threading
+import time
-# ======================
-# CONFIG
-# ======================
+import scanner
-NETWORK = "192.168.1.0/24"
-SCAN_DELAY = 5
-COMMON_PORTS = {
- 22: "SSH",
- 80: "HTTP",
- 443: "HTTPS",
- 445: "SMB",
-}
+SCAN_INTERVAL = 5
+
+devices_cache = {}
-devices = {}
# ======================
-# CORE SCANNER (CHAOS EDITION)
+# SCAN LOOP
# ======================
-def check_host(ip):
- try:
- socket.create_connection((str(ip), 80), timeout=0.2)
- return True
- except:
- return False
-
-
-def scan_ports(ip):
- open_ports = []
-
- for port in COMMON_PORTS.keys():
- try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.settimeout(0.2)
- result = sock.connect_ex((str(ip), port))
- if result == 0:
- open_ports.append(f"{port}:{COMMON_PORTS[port]}")
- sock.close()
- except:
- pass
-
- return open_ports
-
+def update_scan():
+ global devices_cache
+ devices_cache = scanner.scan_network()
-def scan_network():
- global devices
- net = ipaddress.ip_network(NETWORK, strict=False)
+def loop_scanner(tree):
- for ip in net.hosts():
-
- ip_str = str(ip)
-
- if check_host(ip):
-
- ports = scan_ports(ip)
-
- devices[ip_str] = {
- "ip": ip_str,
- "ports": ", ".join(ports) if ports else "unknown",
- "status": "alive"
- }
+ while True:
+ update_scan()
+ refresh_ui(tree)
+ time.sleep(SCAN_INTERVAL)
# ======================
-# GUI CHAOS
+# UI UPDATE
# ======================
-def refresh_table(tree):
+def refresh_ui(tree):
tree.delete(*tree.get_children())
- for ip, data in devices.items():
- tree.insert("", "end", values=(data["ip"], data["status"], data["ports"]))
-
+ for ip, data in devices_cache.items():
-def scan_loop(tree):
+ ports = ", ".join(data["ports"]) if data["ports"] else "unknown"
- while True:
-
- scan_network()
- refresh_table(tree)
-
- time.sleep(SCAN_DELAY)
+ tree.insert("", "end", values=(ip, data["status"], ports))
# ======================
-# UI BUILD
+# GUI
# ======================
def build_gui():
root = tk.Tk()
- root.title("NetForge - Spaghetti Monster Edition")
+ root.title("NetForge - 2 File Edition")
root.geometry("800x500")
- title = tk.Label(root, text="NETFORGE", font=("Arial", 20))
- title.pack(pady=10)
+ label = tk.Label(root, text="NETFORGE", font=("Arial", 18))
+ label.pack(pady=10)
cols = ("IP", "STATUS", "PORTS")
@@ -112,25 +63,21 @@ def build_gui():
for c in cols:
tree.heading(c, text=c)
- tree.pack(fill="both", expand=True, padx=10, pady=10)
+ tree.pack(fill="both", expand=True)
btn = tk.Button(
root,
- text="Force Scan Now (optional chaos button)",
- command=lambda: scan_network()
+ text="Manual Scan",
+ command=lambda: update_scan()
)
- btn.pack(pady=5)
+ btn.pack(pady=10)
- thread = threading.Thread(target=scan_loop, args=(tree,))
+ thread = threading.Thread(target=loop_scanner, args=(tree,))
thread.daemon = True
thread.start()
root.mainloop()
-# ======================
-# RUN IT ALL
-# ======================
-
if __name__ == "__main__":
build_gui()