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
dxdf opened this issue Nov 25, 2024 · 3 comments
Open
2 tasks done

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

dxdf opened this issue Nov 25, 2024 · 3 comments
Labels
enhancement New feature or request keep

Comments

@dxdf
Copy link

dxdf 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
@dxdf dxdf added the enhancement New feature or request label Nov 25, 2024
@imShire
Copy link

imShire commented Nov 29, 2024

遇到同样问题,感谢分享

@jeessy2 jeessy2 added the keep label Dec 18, 2024
@Test031
Copy link

Test031 commented Dec 20, 2024

没搞懂如何操作,可以傻瓜一点吗?

@Test031
Copy link

Test031 commented Dec 21, 2024

获取IPv6结果失败! 未能成功执行命令

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request keep
Projects
None yet
Development

No branches or pull requests

4 participants