简体   繁体   English

给定IP地址,在同一子网中查找接口

[英]Given an IP address, find interface on same subnet

I'm trying to create a bash script and a small part of it requires figuring out if, given an IP address of another computer, what interface is on that same network. 我正在尝试创建一个bash脚本,其中的一小部分需要弄清楚,如果给定另一台计算机的IP地址,则该网络上的接口是什么。

So if my computer is has the following interfaces (not including lo): 因此,如果我的计算机具有以下接口(不包括lo):

eth0      Link encap:Ethernet  HWaddr XX
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0

wlan0     Link encap:Ethernet  HWaddr XX
          inet addr:192.168.5.100  Bcast:192.168.5.255  Mask:255.255.255.0

and I know that there is a computer at the following address: 我知道以下地址有台计算机:

192.168.0.101

is there a simple way to extract the answer eth0 ? 有没有一种简单的方法来提取答案eth0

PS This question is NOT asking about getting the the interface given the address of my own computer like this post is . 附言:这个问题不是问有关如何获得接口的问题,因为我的计算机的地址就像这篇文章中的那样

no, the name eth0 is not broadcasted in any way, so there is no way to get it remotely. 不,名称eth0不会以任何方式广播,因此无法远程获取。 it is just a name that is only internally used. 它只是一个名称,仅在内部使用。 You'd have to log into the remote machine (ssh) and get the info using for example ifconfig . 您必须登录到远程计算机(ssh)并使用例如ifconfig获取信息。

if you need the macaddress of the remote machine (on your network) use arp: 如果需要(在网络上)远程计算机的macaddress,请使用arp:

arp 192.168.0.101

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM