获取网口名称

直接输出所有的网口信息

ifconfig | grep -v '^ ' | grep -v '^```bash
ifconfig | awk -F: '/^[^ ]/{print$1}'
ip a | awk -F": " '/^[^ ]/{print$2}'

获取所有的IP

直接输出所有的IP

ifconfig | grep 'inet ' | awk '{print $2}'
ip a | awk '/inet /{print$2}' | sed 's#/.*##'

格式化输入

格式: 网口名称 – IP

#!/bin/bash

for i in `ls /sys/class/net` 
do
    echo -n `ip a show "$i" | awk '$1 ~ /inet$/' |  awk -F "[/ ]+"  '{print $NF," -- ",$3," (IPV4)"}'` 
    ip a show "$i" | awk '$1 ~ /inet6$/' |  awk -F "[/ ]+"  '{print " ",$3," (IPV6)"}'
done

输出示例

lo -- 127.0.0.1 (IPV4)  ::1  (IPV6)
wlp58s0 -- 192.168.1.55 (IPV4) wlp58s0 -- 1.1.1.1 (IPV4)  fe80::938:2963:e75e:e455  (IPV6)