简体   繁体   English

给定与其关联的IP地址,如何获取NIC卡的逻辑名称?

[英]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.

相关问题 使用脚本将Nic卡的IP地址打印到bash - Printing IP address of Nic card to bash using script C编程:检查是否在任何给定的NIC上添加了IP地址 - C Programming: Check if the IP address is added on any given NIC 如何使用Unix命令或php获取与给定IP地址关联的所有域? - How can I get all of the domains associated with a given ip address using Unix commands or php? 可以在同一NIC上具有PPPoE和单独的静态IP地址吗? - Possible to have PPPoE and separate static IP address on same NIC? 不使用外部程序包即可获取所有NIC的IP地址 - Get IP address of all NIC's without using external package 给定本地linux机器上的IP地址,如何检查它是否被占用? - Given an IP address on local linux machine, how check whether it is occuppied? 检索给定IP地址的Mac地址 - Retrieving Mac Address for the given IP-Address 如何使用终端而不使用网卡在 CentOS 7 中获取 MAC 地址? - How to get MAC address in CentOS 7 using terminal and not using NIC? 给定IP地址,在同一子网中查找接口 - Given an IP address, find interface on same subnet 如何使用外壳程序脚本从dhcp.lease文件中提取IP地址,MAC地址和名称? - How to extract IP address ,MAC address and name from dhcp.lease file with a shell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM