LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2011, 12:00 PM   #1
loadedmind
Member
 
Registered: Sep 2003
Location: Texas
Distribution: Red Hat/CentOS
Posts: 290
Blog Entries: 1

Rep: Reputation: Disabled
arping script


Hi all. The goal is to obtain the MAC address for hosts found on the 192.168.50.0/24 subnet. So, I found this script:

Code:
#!/bin/bash
for i in $(seq 1 254); 
  do 
  echo "arping -q -D -I eth0 -c 2 192.168.50.${i}"; [ $? -ne 0 ] && echo "192.168.50.${i} duplicate"; 
done
This creates the correct arping command for each IP address, but I'm not sure how to get it to execute all arping commands, then send the output to a file somewhere.

Any/all help would be greatly appreciated.
 
Old 12-15-2011, 12:24 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Maybe:
Code:
#!/bin/bash

for i in $(seq 1 254)
do
    ip="192.168.50.$i"
    mac=$(/sbin/arping -c 1 -I eth0 $ip 2>/dev/null | \
            awk '/Unicast/{print $5}' | \
            sed -e 's/\[//' -e 's/\]//')
    if [[ ! $mac = "" ]]; then
            echo "host $ip mac address is: $mac"
    fi
done
edit:
if you have nmap installed, this runs much faster:
(executed as root to get MACs)
Code:
#!/bin/bash

nmap -n -sP 192.168.50.* | \
        awk '/for/{ip = $5};\
        /MAC/{print "host", ip, "mac address is:", $3}'

Last edited by Cedrik; 12-15-2011 at 01:55 PM.
 
1 members found this post helpful.
Old 12-15-2011, 01:49 PM   #3
loadedmind
Member
 
Registered: Sep 2003
Location: Texas
Distribution: Red Hat/CentOS
Posts: 290
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Thanks!

So, to break that script down, you're telling nmap no DNS resolution (-n), then perform a ping scan (-sP). Then, pipe output to awk. This is where I'm a little confused. What is the part after awk doing? Is $5 and $3 taking certain fields from nmap's output somehow?

Last edited by loadedmind; 12-15-2011 at 02:05 PM. Reason: .
 
Old 12-15-2011, 02:43 PM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Yes, you got it. Nothing difficult

$5 : IP (5th field from line that contains word "for")
$3 : Mac address (3rd field from line that contains word "MAC")
$5 is stored in ip variable

Output is controlled at the awk print line.
So if you want output like:
IP = MAC

You just do:
print ip, " = ",$3

Last edited by Cedrik; 12-15-2011 at 03:00 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] arping command for IPV6 shruthi iyer Linux - Networking 1 11-30-2011 07:37 AM
arping doesn't work... jnojr Linux - Networking 3 07-11-2008 02:07 AM
Arping Command saman123 General 0 09-25-2007 06:24 AM
Cannot Ping Gateway , but Can ARPing it ? vivekian Linux - Networking 0 01-31-2007 12:54 PM
shell script - arping doesnt work Bikerpete Programming 8 09-01-2006 01:44 PM


All times are GMT -5. The time now is 03:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration