n

network

psutil 模組可用於獲取 CPU、記憶體、磁碟、網路、進程等系統資源資訊,適用於系統監控、效能分析與資源管理工具。

0 0 0 1
1 import psutil
2
3 # 獲取 CPU 使用率
4 cpu_usage = psutil.cpu_percent(interval=1)
5 print(f"CPU 使用率: {cpu_usage}%")
6
7 # 獲取記憶體資訊
8 memory_info = psutil.virtual_memory()
9 print(f"總記憶體: {memory_info.total / (1024**3):.2f} GB")
10 print(f"可用記憶體: {memory_info.available / (1024**3):.2f} GB")

這段 Bash 腳本設定了 環境變數(如 PATH 和 TZ 時區為 台北時間),然後執行 arp-scan 指令來掃描本地網路(--localnet)的 所有設備的 MAC 和 IP 地址。此腳本適用於 網路管理、設備偵測、安全監控 或 尋找局域網內的未知設備,但需要 root 權限 才能執行 arp-scan。

0 0 0 1
1 #!/bin/bash
2
3 # 定義預設的配置設定
4 SHELL=/bin/sh
5 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
6 TZ='Asia/Taipei'
7
8 # 將配置設定寫入環境變數
9 export PATH
10 export LANG=en_US.UTF-8
Last active 5 hours ago caching dhcp dns dnsmasq firewall network security

這份 dnsmasq 設定檔 用於 管理 DNS 和 DHCP 服務,提供 本機網路名稱解析、靜態 IP 配置、DNS 轉發、快取與封鎖特定域名。它設定了 Google、Hinet 作為上游 DNS,開啟 DNS 查詢日誌,並定義 DHCP 位址範圍、靜態 IP 綁定與特定域名解析。適用於 內部網路架構、加速 DNS 解析、提升隱私安全及廣告封鎖 等場景。

0 0 0 1
1 bogus-priv # Block fake private IP responses
2 no-resolv # Ignore /etc/resolv.conf for upstream DNS
3 dns-forward-max=150 # Limit parallel DNS queries to 150
4 clear-on-reload # Clear cache when dnsmasq reloads
5 domain-needed # Ignore queries without a domain name
6 no-negcache # Do not cache negative (non-existent) DNS responses
7 no-poll # Do not poll /etc/resolv.conf for changes
8 strict-order # Use upstream DNS servers in the order they are listed
9
10 # AdGuard DNS 封鎖廣告和追蹤器。