ip link show type

 

ip -details link show

 

 

type在第三行, loopback 物理 wifi等没有type

 

复制代码
ip -details -json link show | jq --join-output '
.[] |
    if .ifname != null then
        .ifname,
        " ",
        if .linkinfo.info_kind != null then
            .linkinfo.info_kind
        else
            empty
        end,
        " ",
        if .linkinfo.info_slave_kind != null then
            .linkinfo.info_slave_kind
        else
            empty
        end,
        "\n"
    else
        empty
    end
'
复制代码

 

复制代码
#!/bin/bash

# Arguments: $1: Interface ('grep'-regexp).
# For virtual devices, device type is shown on the third line.

# Static list of types (from `ip link help`). NOTE: On my machine, not all types are listed there, e.g. the type `tun`. And the list of types may change over time. So do not ultimately rely on this list here!:
TYPES=(bareudp bond bond_slave bridge can dummy erspan geneve gre gretap hsr ifb ip6erspan ip6gre ip6gretap ip6tnl ipip ipoib ipvlan ipvtap lowpan macsec macvlan macvtap netdevsim nlmon rmnet sit tap tun vcan veth vlan vrf vti vxcan vxlan xfrm)

iface="$1"

for type in "${TYPES[@]}"; do
  ip link show type "${type}" | grep -E '^[0-9]+:' | cut -d ':' -f 2 | sed 's|^[[:space:]]*||' | while read _if; do
    echo "${_if}:${type}"
  done | grep "^${iface}"
done
true
复制代码

 

最好脚本

( sudo ip -details -j l | jq -r '.[]|"@", .ifname, .link_type, .linkinfo.info_data.type, .linkinfo.info_kind, .linkinfo.info_slave_kind'  | tr '\n' ' ' | tr '@' '\n' ; echo ) | column -t

 

 

networking - How to determine the logical type of a linux network device - Unix & Linux Stack Exchange

iproute - iproute2: How to display the TYPE of a network devices? - Unix & Linux Stack Exchange

posted @   ascertain  阅读(230)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-01-08 ssh远程执行nohup命令不退出
点击右上角即可分享
微信分享提示