Skip to content

Commit 2b41047

Browse files
committed
feat: update NetworkManagerDispatcherScripts
1 parent 963d45c commit 2b41047

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

hosts/idols-ai/default.nix

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,65 @@ rec {
5454
source = pkgs.writeText "upHook" ''
5555
INTERFACE=$1
5656
STATUS=$2
57+
58+
get_ip_info(){
59+
# 获取IPv4地址
60+
IPV4_ADDR=$(ip -4 addr show dev $INTERFACE 2>/dev/null | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1)
61+
62+
# 获取IPv6地址(全局范围)
63+
IPV6_ADDR=$(ip -6 addr show dev $INTERFACE 2>/dev/null | grep -oP '(?<=inet6\s)[0-9a-f:]+' | grep -v '^fe80:' | head -n1)
64+
65+
# 获取公网IP(如果有网络连接)
66+
PUBLIC_IP=$(curl -s -4 ifconfig.co 2>/dev/null || curl -s -6 ifconfig.co 2>/dev/null || echo "N/A")
67+
68+
# 构建IP信息字符串
69+
IP_INFO=""
70+
if [ -n "$IPV4_ADDR" ]; then
71+
IP_INFO="IPv4: $IPV4_ADDR"
72+
fi
73+
if [ -n "$IPV6_ADDR" ]; then
74+
if [ -n "$IP_INFO" ]; then
75+
IP_INFO="$IP_INFO, IPv6: $IPV6_ADDR"
76+
else
77+
IP_INFO="IPv6: $IPV6_ADDR"
78+
fi
79+
fi
80+
if [ -n "$PUBLIC_IP" ] && [ "$PUBLIC_IP" != "N/A" ]; then
81+
IP_INFO="$IP_INFO, Public: $PUBLIC_IP"
82+
fi
83+
84+
echo "''${IP_INFO:-No IP addresses found}"
85+
}
86+
5787
notify_status(){
5888
alias_for_work=/etc/agenix/alias-for-work.bash
5989
if [ -f $alias_for_work ]; then
6090
. $alias_for_work
6191
else
6292
echo "No alias file found for work"
6393
fi
64-
MSG="PC[r9000p2025][nixos] online(Device Interface: $DEVICE_IFACE, Connection: $CONNECTION_ID($CONNECTION_UUID), Status: $STATUS, Time: $(date +%Y-%m-%dT%H:%M:%S%Z))"
65-
notify-send $MSG
66-
${pkgs.ntfy-sh}/bin/ntfy publish $ntfy_topic $MSG
94+
95+
# 获取IP信息
96+
IP_INFO=$(get_ip_info)
97+
98+
MSG="PC[r9000p2025][nixos] online(Device Interface: $DEVICE_IFACE, Connection: $CONNECTION_ID($CONNECTION_UUID), Status: $STATUS, IP: $IP_INFO, Time: $(date +%Y-%m-%dT%H:%M:%S%Z))"
99+
notify-send "Network Status" "$MSG"
100+
${pkgs.ntfy-sh}/bin/ntfy publish $ntfy_topic "$MSG"
67101
}
102+
68103
anonymous(){
69104
~/.config/*/scripts/tp_link_script http://192.168.0.1 111111 "$(cat /sys/class/net/wlp0s20f3/address)" "匿名主机" 0
70105
}
71106
72107
case "$STATUS" in
73108
up)
109+
# 等待一下确保IP地址已经分配
110+
sleep 2
74111
notify_status
75112
anonymous
76113
;;
77114
vpn-up)
115+
sleep 2
78116
notify_status
79117
anonymous
80118
;;

0 commit comments

Comments
 (0)