Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

获取最新有效期 ipv6 地址 #1327

Open
2 tasks done
oktty opened this issue Nov 25, 2024 · 0 comments
Open
2 tasks done

获取最新有效期 ipv6 地址 #1327

oktty opened this issue Nov 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@oktty
Copy link

oktty commented Nov 25, 2024

Description

获取最新valid_lft时间的ipv6

  • ip a命令可以查看到网口ip地址,存在多个ipv6,每个ipv6都有valid_lftpreferred_lft时间,获取最新的valid_lft有效时间(最大值);当然你可以用将下面命令中valid_lft换成preferred_lft(其实两者效果一样)

  • 使用valid_lft

    ip -6 a | awk -F '[ \t]+|/' '/inet6/ && $3 != "::1" && $3 !~ /^fe80::/ && $3 !~ /^fda8:/ {ipv6=$3; getline; if ($2=="valid_lft") {split($3, t, "sec"); if (t[1] > max) {max=t[1]; best=ipv6}}} END {print best}'
  • 使用preferred_lft

    ip -6 a | awk -F '[ \t]+|/' '/inet6/ && $3 != "::1" && $3 !~ /^fe80::/ && $3 !~ /^fda8:/ {ipv6=$3; getline; if ($4=="preferred_lft") {split($5, t, "sec"); if (t[1] > max) {max=t[1]; best=ipv6}}} END {print best}'

    $3 !~ /^fe80::/是用于排除已fe80::开头的ipv6;需要排除其他已xxxx开头的ipv6自行添加

Problem

No response

Other Description

No response

Checklist

  • I am using the latest version and have confirmed that the feature is not yet implemented in the latest version
  • I have searched for similar feature requests before submitting this one
@oktty oktty added the enhancement New feature or request label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant