Find IP address of directly connected device
Asked Answered
E

5

30

Is there a way to find out the IP address of a device that is directly connected to a specific ethernet interface? I.e. given one host, one wired ethernet connection and one second host connected to this wired connection, which layer or protocol below IP could be used to find this out.

I would also be comfortable with a Windows-only solution using some Windows-API function or callback.

(I know that the real way to do this would probably via DHCP, but this is about discovering a legacy device.)

Emoryemote answered 25/5, 2011 at 17:45 Comment(1)
If both devices can connect to internet then do that, then check the default gateway to see all connected devices?Names
P
12

To use DHCP, you'd have to run a DHCP server on the primary and a client on the secondary; the primary could then query the server to find out what address it handed out. Probably overkill.

I can't help you with Windows directly. On Unix, the "arp" command will tell you what IP addresses are known to be attached to the local ethernet segment. Windows will have this same information (since it's a core part of the IP/Ethernet interface) but I don't know how you get at it.

Of course, the networking stack will only know about the other host if it has previously seen traffic from it. You may have to first send a broadcast packet on the interface to elicit some sort of response and thus populate the local ARP table.

Phonogram answered 31/5, 2011 at 9:15 Comment(0)
C
21

Mmh ... there are many ways. I answer another network discovery question, and I write a little getting started.

Some tcpip stacks reply to icmp broadcasts. So you can try a PING to your network broadcast address.

For example, you have ip 192.168.1.1 and subnet 255.255.255.0

  1. ping 192.168.1.255
  2. stop the ping after 5 seconds
  3. watch the devices replies : arp -a

Note : on step 3. you get the lists of the MAC-to-IP cached entries, so there are also the hosts in your subnet you exchange data to in the last minutes, even if they don't reply to icmp_get.

Note (2) : now I am on linux. I am not sure, but it can be windows doesn't reply to icmp_get via broadcast.

Is it the only one device attached to your pc ? Is it a router or another simple pc ?

Cimabue answered 13/11, 2011 at 9:35 Comment(3)
What about if the address isn't in the 192.168.1.0/24 subnet?Burglar
@Burglar if it isn't in the same ip subnet, this method doesn't work. the only other method I know will work is snmp-get, try to read the remote device interfaces tables, but it requires 1) snmp daemon on the remote host 2) a community with read access to that hostCimabue
Oh I forgot my case was for the posix environment.Burglar
P
12

To use DHCP, you'd have to run a DHCP server on the primary and a client on the secondary; the primary could then query the server to find out what address it handed out. Probably overkill.

I can't help you with Windows directly. On Unix, the "arp" command will tell you what IP addresses are known to be attached to the local ethernet segment. Windows will have this same information (since it's a core part of the IP/Ethernet interface) but I don't know how you get at it.

Of course, the networking stack will only know about the other host if it has previously seen traffic from it. You may have to first send a broadcast packet on the interface to elicit some sort of response and thus populate the local ARP table.

Phonogram answered 31/5, 2011 at 9:15 Comment(0)
S
12

Windows 7 has the arp command within it. arp -a should show you the static and dynamic type interfaces connected to your system.

Subastral answered 3/12, 2017 at 16:26 Comment(1)
Thank you! This is all I needed to know - "arp -a" showed me the IP address I needed to ping and ssh into for my Raspberry Pi.Implosion
D
6

Your Best Approach is to install Wireshark, reboot the device wait for the TCP/UDP stream , broadcasts will announce the IP address for both Ethernet ports This is especially useful when the device connected does not have DHCP Client enabled, then you can go from there.

Diarmid answered 29/3, 2016 at 11:32 Comment(0)
B
1

You can also get information from directly connected networking devices, such as network switches with LDWin, a portable and free Windows program published on github:

http://www.sysadmit.com/2016/11/windows-como-saber-la-ip-del-switch-al-que-estoy-conectado.html

LDWin supports the following methods of link discovery: CDP (Cisco Discovery Protocol) and LLDP (Link Layer Discovery Protocol).

You can obtain the model, management IP, VLAN identifier, Port identifier, firmware version, etc.

Birddog answered 13/11, 2016 at 19:51 Comment(1)
This did not work for me on Windows 11Shericesheridan

© 2022 - 2024 — McMap. All rights reserved.