LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 11-28-2003, 05:49 PM   #1
bojo
LQ Newbie
 
Registered: Nov 2003
Location: vancouver, bc
Distribution: Mandrake 9.2
Posts: 6

Rep: Reputation: 0
how to find IP if I have MAC address


Hi Guys,
I have to find the IP address of a device when I know only the MAC address. Is it possible? The best would be if I can find a bit more - like if it is a computer or printer etc. In this scenario I have only a switch between the devices.
Thanks,
bojo
 
Old 11-28-2003, 07:27 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
If you know the range of ip addresses like 192.168.0.1 to 50 you could use this bash script to get a list of ip addresses and matching mac addresses.

Also, it's good to know that the first 3 bytes are manufacturer codes. If you look at this site, it may help you identify whether it's a printer or computer. For instance....
08 00 09 is likely a HP printer.
08 00 09 may be a Matsushita copier/printer.
08 00 37 may be a Fjitsu/Xerox printer of some sort.

http://www.synapse.de/ban/HTML/P_LAY.../P_lay207.html

To run the script, type: sh scanmac 192.168.0.1 192.168.0.50
_____________________________________________________

#!/bin/bash

if [ -z "$1" -o "$1" == "-?" ] ; then
echo "Usage: scanmac starting-ip [ending-ip]"
echo
echo "Will list IP and MAC adresses of all active computers"
echo "within a physical network segment."
echo
echo "If ending-ip is omitted, ending-ip = starting-ip+1"
echo " (so that only the host specified will be scanned)."
echo
echo "If you wish to scan from 192.168.2.1 to 192.168.2.31,"
echo " inclusive, specify ending-ip to be 192.168.2.32."
echo

exit 0
fi

startw=$(echo "$1" | cut -d. -f1)
startx=$(echo "$1" | cut -d. -f2)
starty=$(echo "$1" | cut -d. -f3)
startz=$(echo "$1" | cut -d. -f4)

echo "Starting address: $startw.$startx.$starty.$startz"

endip="$2"

if [ -z "$endip" ] ; then
if [ $startz -eq 255 ] ; then
endz=0

if [ $starty -eq 255 ] ; then
endy=0

if [ $startx -eq 255 ] ; then
endx=0

if [ $startw -eq 255 ] ; then
echo "Sorry, you cannot just scan 255.255.255.255."
echo " Maybe later, or you can try to hack support in."

exit 1
else
endw=$(($startw+1))
fi
else
endx=$(($startx+1))
fi
else
endy=$(($starty+1))
fi
else
endz=$(($startz+1))
fi

endip=$endw.$endx.$endy.$endz
fi

echo "Ending address: $endip"

currentw=$startw
currentx=$startx
currenty=$starty
currentz=$startz

currentip=$currentw.$currentx.$currenty.$currentz

# If the bottom octet is zero, it'll get logged inside the while, so
# don't do it here

if [ "$currentz" -ne "0" ] ; then
echo "$(date): $currentip"
fi

trap "exit 15" 15
trap "exit 2" 2

while [ "$currentip" != "$endip" ] ; do
currentip=$currentw.$currentx.$currenty.$currentz

# another log message whenever the bottom octet rolls over

if [ "$currentz" -eq "0" ] ; then
echo "$(date): $currentip"
fi

ping -c 1 -w 10 $currentip >/dev/null 2>&1

mac=$(arp -a $currentip | cut -d' ' -f4)

case "$mac" in
?incomplete?)
: # do nothing -- no MAC for this IP
;;
entries)
: # again, do nothing -- this is a broadcast address
;;
*)
echo "IP: $currentip -- MAC: $mac"
;;
esac

mac="" # reset for the next loop iteration

# now increment the ip values (w,x,y,z)

if [ $currentz -eq 255 ] ; then
currentz=0
else
currentz=$(($currentz+1))
continue
fi

if [ $currenty -eq 255 ] ; then
currenty=0
else
currenty=$(($currenty+1))
continue
fi

if [ $currentx -eq 255 ] ; then
currentx=0
else
currentx=$(($currentx+1))
continue
fi

if [ $currentw -eq 255 ] ; then
break
else
currentz=$(($currentz+1))
continue
fi
done
 
Old 11-28-2003, 08:38 PM   #3
bojo
LQ Newbie
 
Registered: Nov 2003
Location: vancouver, bc
Distribution: Mandrake 9.2
Posts: 6

Original Poster
Rep: Reputation: 0
Smile thanks a lot

it works prety good thanks a lot!
 
Old 11-29-2003, 10:10 PM   #4
zaphodiv
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 388

Rep: Reputation: 30
arp -a will list the MAC and ip addresses of other computers on the LAN that your computer has heard reccently.
 
  


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
How to find an IP address from the MAC address of a remote machine ? jitz Linux - General 3 01-03-2006 07:55 AM
How to find IP address of a machine if I know their MAC Address dysenteryduke Linux - Networking 13 09-12-2005 10:21 AM
How to find MAC address of a specified IP address ? longtongfish Programming 1 07-12-2005 03:26 PM
how can i find mac address compzoo Linux - Networking 3 02-03-2005 02:02 PM
how to find out my MAC address gexiaofei Linux - Software 9 08-18-2003 12:08 PM


All times are GMT -5. The time now is 04:24 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration