3

Possible Duplicates:
how to find MAC address in MAC OS X programmatically ?
How do I query the ARP table on iPhone?

How can I get the MAC address of another device or computer, if I know its IP address?

For example I have:

NSString * ip = @"192.168.1.1";
Community
  • 1
  • 1
Vlad Polyanskiy
  • 2,589
  • 2
  • 18
  • 21
  • Correct me if I'm wrong, but MAC addresses are assigned to your network interface hardware and have nothing to do with a LAN IP. – raidfive May 28 '11 at 18:37
  • @raidfive I think he wants the MAC address of the network interface hardware which is assigned that IP address. For example, I am connected to my network with both ethernet and Wi-Fi, both with a unique IP and a unique MAC address. –  May 28 '11 at 18:39
  • Yeah, MAC assigned to hardware, but i think there is some way to get it wit objective-c. I know how to easily do it with c#. – Vlad Polyanskiy May 28 '11 at 18:42
  • no, i have read http://stackoverflow.com/questions/677530/how-can-i-programmatically-get-the-mac-address-of-an-iphone but it only describes how to get MAC of iPhone. – Vlad Polyanskiy May 28 '11 at 18:44
  • Radek S rights. I need the MAC address of the network interface hardware which is assigned that IP address – Vlad Polyanskiy May 28 '11 at 18:46
  • @Josh Caswell - no. i read that topic and dont find answer. Its like a topic about iPhone above which describes how to get mac of Mac or Iphone on that device directly. I need to get MAC of some unknown device only when i know its IP address. – Vlad Polyanskiy May 28 '11 at 19:03
  • 1
    @Vlad, take a look [How do I query the ARP table on iPhone?](http://stackoverflow.com/questions/2258172/how-do-i-query-the-arp-table-on-iphone) Your question is a duplicate of it. – Black Frog May 28 '11 at 22:38
  • @Black Frog, yeah, its what i really need - thank you very much. – Vlad Polyanskiy May 29 '11 at 09:25

1 Answers1

1

You have to look up the ARP (Address Resolution Protocol) table for the local network. From a Terminal window you can do arp -a at the command line and it will print out the ARP table which shows the local network IP addresses and their physical address associations (the MAC addresses). OSX stores the ARP entries in the system routing tables, but I can't find any good references that show how to translate the entries in the system routing table to MAC addresses: I'm betting there is a sysctl call somewhere, but who knows? There is one unanswered question at Getting routing table on MACOSX (programmatically) that may help, but...

On OSX, the arp detail is at http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man4/arp.4.html: I'd honestly suggest just doing a system call and filtering the results for your desired IP address.

Community
  • 1
  • 1
Femi
  • 64,273
  • 8
  • 118
  • 148
  • i forgot to tell, i need to resolve mac from iOS device. – Vlad Polyanskiy May 28 '11 at 19:42
  • Yeah, you're probably out of luck: not sure that you have any access to the system routing table from client code on the iOS platform, and I'm pretty sure there is no way to invoke the `arp` command line client from an iOS app. – Femi May 28 '11 at 19:50