How to Retrieve Remote MAC Address Programmatically
2009-12-07 14:06
429 查看
Cited From: http://zachwaugh.com/2009/03/programmatically-retrieving-ip-address-of-iphone/
#include <ifaddrs.h>
#include <arpa/inet.h>
- (NSString *)getIPAddress
{
NSString *address = @”error”;
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces – returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL)
{
if(temp_addr->ifa_addr->sa_family == AF_INET)
{
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@”en0″])
{
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}
#include <ifaddrs.h>
#include <arpa/inet.h>
- (NSString *)getIPAddress
{
NSString *address = @”error”;
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces – returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL)
{
if(temp_addr->ifa_addr->sa_family == AF_INET)
{
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@”en0″])
{
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}
相关文章推荐
- How to change MAC address in windows 7
- Java_How To Get MAC Address
- How to change MAC address in windows 7
- How to change MAC address
- How to got the Mac address from …
- [Mac]How to delete all .svn folders under current folder?
- How to resolve "your security settings have blocked an untrusted application from running" in Mac
- Three ways to get your MAC address
- How to Enable the "root" Account on Mac OS X
- Hack Like a Pro: How to Kill and Disable Antivirus Software on a Remote PC
- How to Fix a Hosed /etc/sudoers File on Mac OSX
- How to connect multi-monitors to mac pro
- How to upgrade Git to latest version on Mac OS X?
- How to access a Window XP Remote Destop in a ipv6 network
- How to Run PowerShell Commands on Remote Computers
- How to Install VirtualBox and Windows on your Mac
- How to install Windows on your Mac for free
- How do I change the FROM address to a friendly name?
- How do I get a MAC address via command line?
- How To Monitor Remote Linux Host using Nagios 3.0