Shell 获取网卡名称及对应ip脚本

以下是一个使用 ifconfig 获取网卡名及对应 IP 的简单 Shell 脚本:

#!/bin/bash
echo "网卡名和对应 IP:" > output.txt
# 使用 ifconfig 命令获取网卡信息,并使用 awk 进行处理
ifconfig | awk '/^[a-zA-Z0-9]+/{interface=$1; next} /inet /{print interface ": " $2}' >> output.txt
echo "结果已保存到 output.txt 文件中。"

这个脚本首先运行 ifconfig 命令获取系统的网络配置信息,然后使用 awk 提取网卡名和对应 IP 地址,并最终输出。请注意,该脚本可能需要在具有适当权限的系统上运行。

posted @   Lz_蚂蚱  阅读(469)  评论(0编辑  收藏  举报
(评论功能已被禁用)
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起