DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 10th November 2008
rex rex is offline
Real Name: Nikhil Rathod
Shell Scout
 
Join Date: May 2008
Location: Chicago
Posts: 114
Default MAC address to IP

Is there a way be which I can find IP address on a device on the LAN of which I know the MAC address.

I'm trying to automate something for which I need to know the IP of the device which may change. As I'll be using it in the perl script and hopefully port it to C/C++ in future I need a way to do it from the CLI no GUI tool .
Reply With Quote
  #2   (View Single Post)  
Old 10th November 2008
anomie's Avatar
anomie anomie is offline
Local
 
Join Date: Apr 2008
Location: Texas
Posts: 445
Default

% arp -a | grep 'mac_address_here'

?
__________________
Kill your t.v.
Reply With Quote
  #3   (View Single Post)  
Old 10th November 2008
rex rex is offline
Real Name: Nikhil Rathod
Shell Scout
 
Join Date: May 2008
Location: Chicago
Posts: 114
Default

Quote:
Originally Posted by anomie View Post
% arp -a | grep 'mac_address_here'

?
problem with this is that it'll work only if that device is in my arp table. Isn't there a way in which LAN can be quarried for MAC address.
Reply With Quote
  #4   (View Single Post)  
Old 10th November 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

If you mean queried, no.. sounds like you need to brush up on your basic networking skills.

When a system on your network attempts to connect to an IP address, an action not unlike a DNS lookup occurs.

Host #1 broadcasts a "Who is Host #2" message to the subnet, Host #2 notices this request and responds to Host #1 saying "That's me, I'm Host #2!".

Can you determine the MAC address of every system? Yes.. via brute force, there is no passive method I'm aware of.
Reply With Quote
  #5   (View Single Post)  
Old 10th November 2008
anemos's Avatar
anemos anemos is offline
Fdisk Soldier
 
Join Date: May 2008
Location: Ελλάδα
Posts: 53
Default

Quote:
Originally Posted by rex View Post
Isn't there a way in which LAN can be quarried for MAC address.
The network itself? No.
How do your machines get IP addresses?
Is there any dedicated DHCP server?
If yes, what's the OS? Could you query your server's arp cache through your perl script?
If no (i.e. your router has a DHCP server role as well), I'm afraid you can't do much, apart from trying to find a way to keep your arp cache up-to-date.
Reply With Quote
  #6   (View Single Post)  
Old 10th November 2008
rex rex is offline
Real Name: Nikhil Rathod
Shell Scout
 
Join Date: May 2008
Location: Chicago
Posts: 114
Default

Quote:
How do your machines get IP addresses?
My machine gets IP from DHCP server, But the devices are assigned static IP but the people in charge of those devices keep on changing the IP.
Quote:
Is there any dedicated DHCP server?
There must be a DHCP derver, but as those devices are assigned ststic IP I dont know if there's any point querring DHCP server on top of that half of the subnet IP are reserved of static assignments so DHCP server will not use those IP.
Quote:
If yes, what's the OS? Could you query your server's arp cache through your perl script?
Chances are that it could be a cysco router. But I don't know network administrator will allow me to do that.
Quote:
If no (i.e. your router has a DHCP server role as well), I'm afraid you can't do much, apart from trying to find a way to keep your arp cache up-to-date.
Hmm. Then I'll need to have entire 10.30.1.X subnet into my systems arp cache. One way I could of ding this is to ping all devices (could be very time consuming) and what if I just finished runing ping and somebody changed the IP of one of the devices .

I think I'll have to come up with some other way.
Reply With Quote
  #7   (View Single Post)  
Old 10th November 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

checkout arpwatch: ftp://ftp.ee.lbl.gov/arpwatch.tar.gz

or maybe this might do:
Code:
#!/bin/sh
# -ephemera

net=10.30.1             # 10.30.1/24

[ $# -lt 1 -o `id -u` -ne 0 ] && exit 1
x=1
while [ $x -le 254 ] ; do
	arp -d $net.$x >/dev/null 2>&1 
        printf "\rScanning $net.$x "
        ping -c3 $net.$x 1>/dev/null &
        x=$(($x + 1)) 
done
while [ `pgrep -P $$ ping | wc -l` -ne 0 ] ; do
        printf .
        sleep 1
done
printf " Done.\n"   
arp -na | grep $1 | sed 's/.*(\(.*\)) at .*/\1  /'
# ./script 0a:0b:0c:0d:0e:ff

Last edited by ephemera; 10th November 2008 at 10:04 PM.
Reply With Quote
  #8   (View Single Post)  
Old 11th November 2008
phoenix's Avatar
phoenix phoenix is offline
Risen from the ashes
 
Join Date: May 2008
Posts: 696
Default

To fill your arp table, just ping the broadcast address for the subnet. For example: ping 192.168.0.255. That will cause every machine on that subnet to respond, and you will get arp entries for every machine on the subnet.

Check the output of ifconfig for the current broadcast address.
__________________
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
Reply With Quote
  #9   (View Single Post)  
Old 11th November 2008
anomie's Avatar
anomie anomie is offline
Local
 
Join Date: Apr 2008
Location: Texas
Posts: 445
Default

Quote:
Originally Posted by ephemera View Post
+1

arpwatch is a really handy (passive) layer 2 sniffer that can help identify network problems.

---

I'd also add to all this:

Quote:
Originally Posted by rex
But the devices are assigned static IP but the people in charge of those devices keep on changing the IP.
This is the real problem. The network needs to be better managed, IMO. We don't call one another up and say "hey, can I get your MAC address?" for network communication purposes. There should be a coherent network design and a better change control process in place.
__________________
Kill your t.v.
Reply With Quote
Old 11th November 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

Phoenix,

As in the OP's case, suppose host A has an entry in the arp cache for host B. B changes its IP before A's arp cache expires.
Now if A tries to send a packet (using the stale cache entry) to B then what will happen?
And is it documented or implementation dependent?

Last edited by ephemera; 11th November 2008 at 07:14 PM.
Reply With Quote
Reply

Tags
arp, ip, mac

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to test whether an IP address has been listed in a DNSBL J65nko Guides 12 2nd February 2016 03:30 AM
could not look up internet address for .lan idefix FreeBSD General 2 31st January 2009 02:22 PM
Changing MAC address to an alias interface? DNAeon FreeBSD General 6 20th January 2009 04:48 PM
Static IP address problem rex FreeBSD General 2 25th November 2008 08:53 PM
Asking about IPv6 address berlowin Off-Topic 2 9th July 2008 02:39 AM


All times are GMT. The time now is 11:13 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick