How to fetch the logical name of a NIC card given the ip address associated with it ?

泪湿孤枕 提交于 2019-12-21 19:26:09

问题


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?


回答1:


Take this:

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


来源:https://stackoverflow.com/questions/17476248/how-to-fetch-the-logical-name-of-a-nic-card-given-the-ip-address-associated-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!