finnoscarmax/network-scanner-tool

GitHub: finnoscarmax/network-scanner-tool

一款用于扫描附近 Wi‑Fi 网络并记录信号强度的 Python 教学工具,解决近距离无线网络发现与信号监控问题。

Stars: 0 | Forks: 0

# network-scanner-tool 用于扫描附近 Wi-Fi 网络并记录信号强度的 Python 工具。开发中。 Network Scanner Tool - 仅供学习使用 作者:finn-oscar-max 最后更新:2026 年 3 月 30 日 import subprocess import json import datetime import hashlib from typing import List, Dict class NetworkScanner: ``` Scans nearby Wi-Fi networks and logs access points. def __init__(self, interface: str = "wlan0"): self.interface = interface self.scan_results = [] self.log_file = "scan_log.json" def scan_networks(self) -> List[Dict]: """ Execute iwlist scan and parse results. """ try: output = subprocess.check_output( ["sudo", "iwlist", self.interface, "scan"], stderr=subprocess.DEVNULL, text=True ) return self._parse_scan(output) except subprocess.CalledProcessError: print("[ERROR] Scan failed. Check interface.") return [] def _parse_scan(self, raw_output: str) -> List[Dict]: """ Parse iwlist output into structured data. """ networks = [] current = {} for line in raw_output.split('\n'): line = line.strip() if 'Cell' in line: if current: networks.append(current) current = {} elif 'Address:' in line: current['bssid'] = line.split('Address: ')[1] elif 'ESSID:' in line: essid = line.split('ESSID:"')[1].rstrip('"') current['ssid'] = essid if essid else "[HIDDEN]" elif 'Quality=' in line: quality = line.split('Quality=')[1].split(' ')[0] current['signal'] = quality elif 'Encryption key:' in line: current['encrypted'] = 'on' in line.lower() if current: networks.append(current) return networks def log_results(self, networks: List[Dict]) -> None: """ Save scan results with timestamp. """ log_entry = { "timestamp": datetime.datetime.now().isoformat(), "networks": networks, "device_id": hashlib.sha256(b"finn-oscar-max").hexdigest()[:8] } with open(self.log_file, 'a') as f: json.dump(log_entry, f) f.write('\n') print(f"[+] Logged {len(networks)} networks to {self.log_file}") def check_signal_strength(self, bssid: str) -> int: """ Monitor specific BSSID for signal changes. Useful for proximity alerts. """ networks = self.scan_networks() for net in networks: if net.get('bssid') == bssid: quality = net.get('signal', '0/100') return int(quality.split('/')[0]) return -1 def run_monitor(self, target_bssid: str, interval: int = 5): """ Continuously monitor a target network. """ print(f"[*] Monitoring {target_bssid} every {interval} seconds...") try: while True: strength = self.check_signal_strength(target_bssid) if strength > 70: print(f"[!] Strong signal detected! Strength: {strength}") elif strength >= 0: print(f"[.] Signal strength: {strength}") else: print(f"[-] Target not found") time.sleep(interval) except KeyboardInterrupt: print("\n[*] Monitoring stopped") ``` if __name__ == "__main__": scanner = NetworkScanner() ``` # 使用示例 networks = scanner.scan_networks() scanner.log_results(networks) for net in networks[:5]: print(f"SSID: {net.get('ssid')} | BSSID: {net.get('bssid')} | Signal: {net.get('signal')}") ```
标签:ETW劫持, Python, Wi-Fi, 信号扫描, 无后门, 日志记录, 网络工具