给定与之关联的IP地址,如何获取NIC卡的逻辑名称? [英] How to fetch the logical name of a NIC card given the ip address associated with it ?

查看:78
本文介绍了给定与之关联的IP地址,如何获取NIC卡的逻辑名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个shell脚本,该脚本需要知道与给定ip关联的逻辑名称(eth0,eth1等).我正在使用的当前过程是使用过滤器解析ifconfig的输出,并获取与给定IP相关的NIC卡.我想知道是否存在更简单的方法或直接管道化的linux命令来获取上述详细信息?

I am working on a shell script which needs to know the logical name (eth0, eth1, etc) associated with a given ip. The current procedure I am employing is to parse the output of ifconfig using filters and getting the NIC card associated with a given IP. I was wondering if there exists a simpler way or a direct pipelined linux command to get the above mentioned detail?

推荐答案

为此:

#!/bin/sh
ip=192.168.1.10
iface=$(ip addr | grep $ip | awk '{print $NF}')
echo "Iface is: ${iface}"

这篇关于给定与之关联的IP地址,如何获取NIC卡的逻辑名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆