[英]How to fetch the logical name of a NIC card given the ip address associated with it ?
I am working on a shell script which needs to know the logical name (eth0, eth1, etc) associated with a given ip. 我正在研究一个shell脚本,它需要知道与给定ip相关的逻辑名称(eth0,eth1等)。 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. 我正在使用的当前过程是使用过滤器解析ifconfig的输出并获取与给定IP关联的NIC卡。 I was wondering if there exists a simpler way or a direct pipelined linux command to get the above mentioned detail? 我想知道是否存在更简单的方法或直接的流水线linux命令来获得上述细节?
Take this: 拿着这个:
#!/bin/sh
ip=192.168.1.10
iface=$(ip addr | grep $ip | awk '{print $NF}')
echo "Iface is: ${iface}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.