Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Script extracting ip address from MAC wifi card

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-30-2014
freddie50 freddie50 is offline
Users Awaiting Email Confirmation
 
Join Date: Jun 2011
Last Activity: 20 June 2016, 4:28 PM EDT
Posts: 50
Thanks: 31
Thanked 0 Times in 0 Posts
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:

Code:
Laptop-Fred=192.168.0.10


Code:
# 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,
Linux

Last edited by Scrutinizer; 10-30-2014 at 05:57 AM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 10-30-2014
ahamed101's Unix or Linux Image
ahamed101 ahamed101 is offline Forum Advisor  
root is god!!!
 
Join Date: Sep 2008
Last Activity: 19 October 2016, 5:02 AM EDT
Location: San Jose, CA
Posts: 1,910
Thanks: 54
Thanked 488 Times in 481 Posts
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
Sponsored Links
    #3  
Old Unix and Linux 10-30-2014
freddie50 freddie50 is offline
Users Awaiting Email Confirmation
 
Join Date: Jun 2011
Last Activity: 20 June 2016, 4:28 PM EDT
Posts: 50
Thanks: 31
Thanked 0 Times in 0 Posts
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,
    #4  
Old Unix and Linux 10-30-2014
ahamed101's Unix or Linux Image
ahamed101 ahamed101 is offline Forum Advisor  
root is god!!!
 
Join Date: Sep 2008
Last Activity: 19 October 2016, 5:02 AM EDT
Location: San Jose, CA
Posts: 1,910
Thanks: 54
Thanked 488 Times in 481 Posts
You didnt answer my 2nd and 3rd question correctly.

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

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

--ahamed
Sponsored Links
    #5  
Old Unix and Linux 10-30-2014
freddie50 freddie50 is offline
Users Awaiting Email Confirmation
 
Join Date: Jun 2011
Last Activity: 20 June 2016, 4:28 PM EDT
Posts: 50
Thanks: 31
Thanked 0 Times in 0 Posts
I apology for being unclear,

2. 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

3. 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,
Sponsored Links
    #6  
Old Unix and Linux 10-30-2014
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 January 2017, 1:26 PM EST
Location: Aachen, Germany
Posts: 10,157
Thanks: 230
Thanked 3,073 Times in 2,849 Posts
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
Code:
LAPTOP_FRED=$(nmap|awk '/Nmap scan report/ {IP=$NF} /X1:X2:3X:X4:X5:Y6/ {print IP}' )

Sponsored Links
    #7  
Old Unix and Linux 10-30-2014
freddie50 freddie50 is offline
Users Awaiting Email Confirmation
 
Join Date: Jun 2011
Last Activity: 20 June 2016, 4:28 PM EDT
Posts: 50
Thanks: 31
Thanked 0 Times in 0 Posts
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,
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trouble with broadcomm card Wifi driver build Mt3ng4 Ubuntu 2 06-18-2011 10:04 PM
Tracing a MAC address to IP address: Solaris DNT IP Networking 9 08-17-2010 09:10 AM
script to compare two files of mac address borderblaster Shell Programming and Scripting 6 10-14-2008 09:45 PM
How to Achive IP address through MAC(Ethernet) address krishnacins IP Networking 3 08-29-2005 09:45 PM
Mac address - what is line command to find and active new card wmetz IP Networking 1 03-19-2002 04:44 PM



All times are GMT -4. The time now is 11:47 PM.