This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 安全 DHCP 偵測(適合遠端 AnyDesk 使用) | |
# 會:記錄現況 → 開 tcpdump → 斷線/重連觸發 DHCP → 自動救援重連 → 解析誰回覆了 DHCP | |
# 用法: | |
# sudo bash ~/safe_dhcp_probe.sh [介面] [監聽秒數] | |
# 例如:sudo bash ~/safe_dhcp_probe.sh enp4s0 20 | |
set -u # 不用 -e,避免個別步驟失敗就整段終止 | |
IFACE="${1:-enp4s0}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 安全 renew DHCP(NetworkManager 版) | |
# 會: | |
# 1) 找出目前預設路由的網卡與連線名稱 | |
# 2) 記錄舊的 IPv4 | |
# 3) down/up 該連線(等同 release/renew) | |
# 4) 等待最多 30 秒拿新 IP;失敗則嘗試重啟 NetworkManager 後再次 up | |
# 5) 若仍失敗,還原到舊連線狀態(再 up 一次) | |
set -o pipefail |