LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-16-2010, 01:24 PM   #1
bostan
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Rep: Reputation: 0
How do I find the mac address for a given ip address?


Hi All,
I am trying to find out the mac address of the eth0 port on linux probe. This port is controlled by kernal and hence I don't have control over it. How do I find out the mac address of this port ? Is there any system call which will take the ip address and will do the lookup on the linux's ip table to get the mac address ?
-Thanks
 
Old 02-16-2010, 01:39 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
From the command line, ifconfig provides the information you want and its output could be parsed by several languages.
 
Old 02-16-2010, 01:42 PM   #3
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
Hi,

you can access the kernel ARP tables with the SIOCSARP, SIOCDARP and SIOCGARP ioctls on any AF_INET socket. See arp(7) for details.

There is also a command line tool called "arp" that can modify and view the ARP tables.
 
Old 02-16-2010, 01:47 PM   #4
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
Maybe also the ioctls SIOCGIFHWADDR, SIOCSIFHWADDR described in netdevice(7) are of interest.
 
Old 02-16-2010, 08:11 PM   #5
bostan
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Original Poster
Rep: Reputation: 0
How do I find the mac address for a given ip address?

Hi ,
Thanks for the info. I tried using ioctl call and when I try to get the arp entry by calling ioctl(s,SIOCGARP,&a) I get the error saying protocol not supported. I am using fedora 12 linux 2,6.22
Am I missing something here ?
 
Old 02-17-2010, 04:04 AM   #6
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
The SIOCGARP ioctl call expects several parameters already set in the request structure. I put two small programs in the appendix: The first one will query the ARP tables for the hardware address belonging to an IP address (this does not work on your own addresses, only on devices, that are on the same subnet). The other one will query for the hwaddress of a local interface.

I hope they will help you with your problem.
Attached Files
File Type: txt arp.c.txt (1.2 KB, 18 views)
File Type: txt hwaddr.c.txt (867 Bytes, 16 views)
 
Old 02-17-2010, 09:28 AM   #7
bostan
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks Irmin
I can see the arp entry now for a given IP address.
-Thanks a lot and God bless you

Last edited by bostan; 02-17-2010 at 09:57 AM.
 
  


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 to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM
how would you find the mac address bhupee Linux - Newbie 5 07-05-2004 06:07 PM


All times are GMT -5. The time now is 01:53 AM.

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