2

I have router in bridge mode which is installed Openwrt and I want to find IP address of devices which are connected to the router. Since router is in bridge mode, I can not find IP from DHCP leases, but I can find mac address of connected devices.

First thing came to mind is broadcast to all network and finding IP address from ARP but this didn't work for me because when I broadcast to the network I can not take response from some of the devices and I am thinking that this may be related my modem's firewall settings.

So, my question is how can I find IP address of device programmatically from mac address ?

Enes Aldemir
  • 21
  • 1
  • 4

3 Answers3

2

Install nmap to your OpenWRT router:

opkg update;opkg install nmap

Scan all network.For example,the network is: 203.120.12.0/24

 nmap -v -sn 203.120.12.0/24 --open

It should show something like this:

Nmap scan report for 203.120.12.253
Host is up (0.00016s latency).
MAC Address: 04:18:D6:83:90:07 (Ubiquiti Networks)

Then u can use the grep command to get IP address from MAC address

Nam Pham
  • 121
  • 3
1

@Nam Pham has the right idea, but here is how you make it into a bash script so you can do it "programmatically":

mac=your.mac.here

#Determine local ip address and use to get domain:
ip=`hostname -I | awk '{print $1}'`
domain=`echo $ip | sed 's/\.[^.]*$/.*/'`

nmap -sn $domain | grep $mac -B2 | head -n 1 | sed 's/.* //'
SurpriseDog
  • 123
  • 5
0

One way to find out the IP address of a device is with a protocol analyser such as wireshark. If you capture enough traffic from a network interface, you should see some broadcast traffic generated by just about every device on the network. You can then filter for packets with a source MAC matching your router.

In wireshark this filter would be eth.src == xx:xx:xx:xx:xx:xx

An advantage of this method is that it works even if your router is using an address outside of your subnet.

IsAGuest
  • 947
  • 9
  • 14
  • I just editted my question, I want to find ip address programmatically because I will use this ip address with another program. So, wireshark does not work for me. – Enes Aldemir May 20 '16 at 12:20