Add net alias and source user_utils file
This commit is contained in:
parent
75163575dd
commit
14addfc9ff
54
files/.user_utils
Normal file
54
files/.user_utils
Normal file
@ -0,0 +1,54 @@
|
||||
#!/bin/zsh
|
||||
|
||||
__is_public_ipv4() {
|
||||
local ip=$1
|
||||
if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
IFS='.' read -r -A ADDR <<< "$ip"
|
||||
if [[ ${ADDR[1]} -eq 10 ]]; then
|
||||
return 1
|
||||
elif [[ ${ADDR[1]} -eq 172 && ${ADDR[2]} -ge 16 && ${ADDR[2]} -le 31 ]]; then
|
||||
return 1
|
||||
elif [[ ${ADDR[1]} -eq 192 && ${ADDR[2]} -eq 168 ]]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
__get_ipv4() {
|
||||
local ipv4=$(ip route get 1.1.1.1 | head -1 | awk '{print $7}')
|
||||
if __is_public_ipv4 $ipv4; then echo "$ipv4"; return 0; fi
|
||||
ipv4=$(ip route get 1.1.1.1 | head -1 | awk '{print $NF}')
|
||||
if __is_public_ipv4 $ipv4; then echo "$ipv4"; return 0; fi
|
||||
ipv4=$(curl -4 -s ifconfig.me)
|
||||
if __is_public_ipv4 $ipv4; then echo "$ipv4"; return 0; fi
|
||||
ipv4=$(host -4 myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}')
|
||||
if __is_public_ipv4 $ipv4; then echo "$ipv4"; return 0; fi
|
||||
echo "No public IPv4 address found"
|
||||
return 1
|
||||
}
|
||||
|
||||
__get_ipv6() {
|
||||
if [[ "$(ip -6 route get 2001:4860:4860::8888 2>&1 | awk '{print $NF}')" == "unreachable" ]]; then
|
||||
echo "No IPv6 connectivity"
|
||||
return 1
|
||||
fi
|
||||
local ipv6=$(ip route get 2001:4860:4860::8888 | head -1 | awk '{print $11}')
|
||||
if [[ $ipv6 =~ ^([0-9a-fA-F]{0,4}:){7}[0-9a-fA-F]{0,4}$ ]]; then echo "$ipv6"; return 0; fi
|
||||
ipv6=$(ip route get 2001:4860:4860::8888 | head -1 | awk '{print $NF}')
|
||||
if [[ $ipv6 =~ ^([0-9a-fA-F]{0,4}:){7}[0-9a-fA-F]{0,4}$ ]]; then echo "$ipv6"; return 0; fi
|
||||
ipv6=$(curl -6 -s ifconfig.me)
|
||||
if [[ $ipv6 =~ ^([0-9a-fA-F]{0,4}:){7}[0-9a-fA-F]{0,4}$ ]]; then echo "$ipv6"; return 0; fi
|
||||
echo "No public IPv6 address found"
|
||||
return 1
|
||||
}
|
||||
|
||||
__get_ip() {
|
||||
__get_ipv4
|
||||
__get_ipv6
|
||||
}
|
||||
|
||||
__get_ipv4
|
||||
@ -151,6 +151,9 @@ fi
|
||||
|
||||
command_exists docker && alias gost='docker run --rm -p 9443:9443 --cpus=0.2 --memory=256mb gogost/gost -L socks5://nano:QpuwAqcsP8Xp@:9443'
|
||||
|
||||
source ~/.user_utils
|
||||
alias net='__get_ip'
|
||||
|
||||
_systemctl_unit_state() {
|
||||
typeset -gA _sys_unit_state
|
||||
_sys_unit_state=( $(__systemctl list-unit-files '$PREFIX*' | awk '{print $1, $2}') )
|
||||
|
||||
@ -79,6 +79,7 @@ configure_nodejs() {
|
||||
# ============================================================
|
||||
|
||||
update_file $scriptdir/files/ys-simple.zsh-theme ~/.oh-my-zsh/themes/ys-simple.zsh-theme
|
||||
update_file $scriptdir/files/.user_utils ~/.user_utils
|
||||
update_authorized_keys
|
||||
|
||||
if [ $# -ne 0 ]; then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user