mirror of
https://github.com/RROrg/rr.git
synced 2025-08-08 13:47:08 +08:00
优化 getIP 函数中的 IP 地址获取顺序
This commit is contained in:
parent
888eef390a
commit
bc1209954f
@ -303,11 +303,11 @@ function getBus() {
|
|||||||
function getIP() {
|
function getIP() {
|
||||||
local IP=""
|
local IP=""
|
||||||
if [ -n "${1}" ] && [ -d "/sys/class/net/${1}" ]; then
|
if [ -n "${1}" ] && [ -d "/sys/class/net/${1}" ]; then
|
||||||
IP=$(ip route show dev "${1}" 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p' | head -1)
|
IP=$(ip addr show "${1}" scope global 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -d'/' -f1 | head -1)
|
||||||
[ -z "${IP}" ] && IP=$(ip addr show "${1}" scope global 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -d'/' -f1 | head -1)
|
[ -z "${IP}" ] && IP=$(ip route show dev "${1}" 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p' | head -1)
|
||||||
else
|
else
|
||||||
IP=$(ip route show 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p' | head -1)
|
IP=$(ip addr show scope global 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -d'/' -f1 | head -1)
|
||||||
[ -z "${IP}" ] && IP=$(ip addr show scope global 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -d'/' -f1 | head -1)
|
[ -z "${IP}" ] && IP=$(ip route show 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p' | head -1)
|
||||||
fi
|
fi
|
||||||
echo "${IP}"
|
echo "${IP}"
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user