Does anyone know how to programmatically get an iPhone's MAC address and IP address?
You can access it using Settings -> General -> About. It is listed under "Wi-fi Address."
If you're talking about doing this programmatically, maybe we should talk about what you're trying to do :)
Somthing I stumbled across a while ago. Originally from here I modified it a bit and cleaned things up.
And to use it
InitAddresses();
GetIPAddresses();
GetHWAddresses();
int i;
NSString *deviceIP = nil;
for (i=0; i<MAXADDRS; ++i)
{
static unsigned long localHost = 0x7F000001; // 127.0.0.1
unsigned long theAddr;
theAddr = ip_addrs[i];
if (theAddr == 0) break;
if (theAddr == localHost) continue;
NSLog(@"Name: %s MAC: %s IP: %s\n", if_names[i], hw_addrs[i], ip_names[i]);
//decided what adapter you want details for
if (strncmp(if_names[i], "en", 2) == 0)
{
NSLog(@"Adapter en has a IP of %@", [NSString stringWithFormat:@"%s", ip_names[i]]);
}
}
Adapter names vary depending on the simulator/device as well as wifi or cell on the device.
Hope that helps.
chris.
Okay this looks nice but I am new to MAC OS X programming.so I want to know can I use the same code for getting MAC address if a iMac or Mac book? If yes what kind of project should I use in X code - command line application or cocoa application? and if not, what changes are required in this code or where can I find he appropriate reference ? thank you.