Script extracting ip address from MAC wifi card

Hi Everybody,

Goal:
From my backup box on my local network, knowing the Wifi MAC address of my laptop, I would like to dynamically identify which ip address is attributed to my laptop.
The aim is to store this ip address in a local variable and that this information is retrieved by another backup script

Problem:
Calling the command nmap, as root user I want to write a script that will extract the ip address from the MAC address of my laptop.

Question:
How would you do that and with which script language?
Shell, perl, python?

Example:
from the result of nmap and with the MAC address X1:X2:3X:X4:X5:Y6, I want to extract:

Laptop-Fred=192.168.0.10
# nmap 
Starting Nmap 6.45 ( Nmap - Free Security Scanner For Network Exploration & Security Audits. ) at 2014-10-30 07:05 CET
Nmap scan report for 192.168.0.1
Host is up (0.0047s latency).
MAC Address: XX:XF:0X:X1:XX:YY (Netgear)
Nmap scan report for 192.168.0.10
Host is up (0.074s latency).
MAC Address: X1:X2:3X:X4:X5:Y6 (Netgear)
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 5.61 seconds

Many thanks for any input!
Keep up the good work.
Cheers,
:slight_smile:

Where do you get the string "Laptop-Fred"?
And do you want to extract the IP from the output of nmap?
Does the mac X1:X2:3X:X4:X5:Y6 corresponds to 192.168.0.10?

--ahamed

Yes,

  1. Absolutely I would like to extract the information from the output of nmap, unless you see another way?

  2. Laptop-Fred would be a variable to store the ip address

  3. X1:X2:3X:X4:X5:Y6 is in this example the MAC address of Laptop Fred Wifi card.

Thank you,

You didnt answer my 2nd and 3rd question correctly.

  1. From where would I get the name "Laptop-Fred"?

  2. Does the mac X1:X2:3X:X4:X5:Y6 corresponds to 192.168.0.10?

--ahamed

I apology for being unclear,

  1. Laptop-Fred was in my mind a shell variable, call it var_laptop_1 if this is better and this vari2ble would have to store the ip address 192.168.0.10 of the laptop we are trying to identify

  2. From the result of nmap in this dhcp configuration the mac address X1:X2:3X:X4:X5:Y6 corresponds to 192.168.0.10

Thank you very much for your help,

There doesn't seem to be a relation between laptop-1 or laptop_fred and the MAC address given. So how should any command/program/script select 192.168.0.10 instead of 192.168.0.1 to place into your variable?

---------- Post updated at 11:58 ---------- Previous update was at 11:54 ----------

For a known MAC address, you could use sth like

LAPTOP_FRED=$(nmap|awk '/Nmap scan report/ {IP=$NF} /X1:X2:3X:X4:X5:Y6/ {print IP}' )

Well, I think there is a relation:
The ip address associated to the MAC address
is the ip address 2 lines above the MAC address.
But how to extract this with a script?
Maybe should I first change the output of nmap?

Thank you so much for your help,

Extracting is easy, see above. Extracting the right, meaningful one is the issue.

Yes, I see.
Could you please confirm the exact nmap command you are using in your exemple?
Many thanks for your help,

I used your sample output, as I don't have nmap around.

If you know the MAC address, use 'arp' to get the IP address.

Thank you so much,
That is exactly what I needed!
Cheers,