Skip to content

Instantly share code, notes, and snippets.

@AshineRong
Created September 7, 2022 07:44
Show Gist options
  • Save AshineRong/6d1dcbaf8d738a15dfbcb2d133ebc506 to your computer and use it in GitHub Desktop.
Save AshineRong/6d1dcbaf8d738a15dfbcb2d133ebc506 to your computer and use it in GitHub Desktop.
#!/bin/bash
KconfigPath="/opt/rcdata/config"
KPWD=`echo $(cat .ENV | grep 'Kpwd' | awk -F '=' '{print $2}')`
ifconfig -l | xargs -n1 ipconfig getifaddr > $KconfigPath/real_ip.txt
real_ip=$(sed -n '1p' $KconfigPath/real_ip.txt)
record_ip=$(sed -n '1p' $KconfigPath/record_local_ip.txt)
if [ $real_ip != $record_ip ]; then
echo "ip 变化"
# 清空DNS缓存
dscacheutil -flushcache
echo ${KPWD} | sudo -S networksetup -setmanual "Ethernet" 10.1.x.x 255.255.248.0 10.1.0.X
# 配置有线的DNS
networksetup -setdnsservers "Ethernet" 114.114.114.114 8.8.8.8 223.5.5.5
# dns 置空,默认分配的dns
networksetup -setdnsservers Wi-Fi empty
# 邮件通知;
ifconfig -l | xargs -n1 ipconfig getifaddr > $KconfigPath/real_ip.txt
real_ip=$(sed -n '1p' $KconfigPath/real_ip.txt)
ruby $KconfigPath/autoMail.rb
# 并修改记录ip
`cat $KconfigPath/real_ip.txt > $KconfigPath/record_local_ip.txt`
else
echo "🎉ip 不变 🎉"
# 清空DNS缓存
# dscacheutil -flushcache
# echo ${KPWD} | sudo -S networksetup -setmanual "Ethernet" 10.x.x.x 255.255.248.0 10.x.0.x
# # 配置有线的DNS
# networksetup -setdnsservers "Ethernet" 114.114.114.114 223.5.5.5 8.8.8.8
# dns 置空,默认分配的dns
# networksetup -setdnsservers Wi-Fi empty
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment