Script Python: deteksi_wifi.py C jalankan (python deteksi_wifi.py) - kelola_whitelist.py

import os import platform import subprocess from datetime import datetime def get_arp_table(): if platform.system() == "Windows": output = subprocess.check_output("arp -a", shell=True, encoding='utf-8') else: output = subprocess.check_output(["arp", "-a"], encoding='utf-8') return output def parse_arp_output(arp_output): devices = [] for line in arp_output.splitlines(): if "-" in line: parts = line.split() if len(parts) >= 2: ip = parts[0] mac = parts[1].lower().replace("-", ":") devices.append((ip, mac)) return devices def load_whitelist(): try: with open("whitelist.txt", "r") as f: return [line.strip().lower() for line in f if line.strip()] except FileNotFoundError: return [] def log_detection(ip, mac): with open("log_deteksi.txt", "a") as f: f.write(f"{datetime.now()} | PERANGKAT ASING | IP: {ip}, MAC: {mac}\n") def main(): whitelist = load_whitelist() arp_output = get_arp_table() devices = parse_arp_output(arp_output) print("🔍 Memindai jaringan...\n") found = False for ip, mac in devices: if mac not in whitelist: found = True print(f"🚨 PERANGKAT ASING TERDETEKSI:\n❌ IP: {ip}, MAC: {mac}") log_detection(ip, mac) if not found: print("✅ Tidak ada perangkat asing ditemukan.") print("\nSelesai.\n") if __name__ == "__main__": main()

Comments

Popular posts from this blog

Contoh Pindah Lokasi di CMD, Folder & Drive C D E

Langkah Cek Instalasi Python

Perbedaan antara Nmap dan python-nmap