#import "deviceinfoutil.h"
#import "globledata.h"
#import "sys/utsname.h"
#import #import #import #import #import #include // per msqr
#include #include #include #define ios_cellular @"pdp_ip0"
#define ios_wifi @"en0"
//#define ios_vpn @"utun0"
#define ip_addr_ipv4 @"ipv4"
#define ip_addr_ipv6 @"ipv6"
@implementation deviceinfoutil
// return the local mac addy
// courtesy of freebsd hackers email list
// accidentally munged during previous update. fixed thanks to mlamb.
- (nsstring *) macaddress
if (sysctl(mib, 6, null, &len, null, 0) < 0)
if ((buf = malloc(len)) == null)
if (sysctl(mib, 6, buf, &len, null, 0) < 0)
ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);
ptr = (unsigned char *)lladdr(sdl);
nsstring *outstring = [nsstring stringwithformat:@"%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
// nsstring *outstring = [nsstring stringwithformat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
nslog(@"outstring:%@", outstring);
free(buf);
return [outstring uppercasestring];
}//獲取ip位址
//獲取裝置當前網路ip位址
- (nsstring *)getipaddress:(bool)preferipv4
]; return address ? address : @"0.0.0.0";
}//獲取所有相關ip資訊
- (nsdictionary *)getipaddresses
const struct sockaddr_in *addr = (const struct sockaddr_in*)inte***ce->ifa_addr;
char addrbuf[ max(inet_addrstrlen, inet6_addrstrlen) ];
if(addr && (addr->sin_family==af_inet || addr->sin_family==af_inet6))
} else
}if(type) }}
// free memory
freeifaddrs(inte***ces);
}return [addresses count] ? addresses : nil;
}- (nsstring *)getmacaddress
if (sysctl(mib, 6, null, &len, null, 0) < 0)
if ((buf = malloc(len)) == null)
if (sysctl(mib, 6, buf, &len, null, 0) < 0)
ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);
ptr = (unsigned char *)lladdr(sdl);
nsstring *outstring = [nsstring stringwithformat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
free(buf);
return [outstring uppercasestring];
}- (void)getdeviceinfo
- (nsstring *)getosinfo
// 獲取裝置型號然後手動轉化為對應名稱
- (nsstring *)getdevicename
- (nsstring *)getdeviceipaddresses
ptr += sizeof(ifr->ifr_name) + len;
if (ifr->ifr_addr.sa_family != af_inet) continue;
if ((cptr = (char *)strchr(ifr->ifr_name, ':')) != null) *cptr = 0;
if (strncmp(lastname, ifr->ifr_name, ifnamsiz) == 0) continue;
memcpy(lastname, ifr->ifr_name, ifnamsiz);
ifrcopy = *ifr;
ioctl(sockfd, siocgifflags, &ifrcopy);
if ((ifrcopy.ifr_flags & iff_up) == 0) continue;
nsstring *ip = [nsstring stringwithformat:@"%s", inet_ntoa(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr)];
[ips addobject:ip];}}
close(sockfd);
nsstring *deviceip = @"";
for (int i=0; i < ips.count; i++)
}return deviceip;
}//獲取登陸使用者id
- (nsstring *)getuserid
//獲取登陸使用者手機號
- (nsstring *)getphonenum
//獲取裝置惟一標示符
- (nsstring *)getuuid
- (nsstring *)getversion
//獲取使用者手機號,uuid,手機型號,版本號,簽名,平台(ios/android)
獲取裝置mac位址
nsstring macaddress if sysctl mib,6,null,len,null,0 0 if buf malloc len null if sysctl mib,6,buf,len,null,0 0 ifm struct if msghdr buf sdl struct sock...
獲取iOS裝置資訊
鑌哥就直接寫 了 獲取手機資訊 應用程式的名稱和版本號等資訊都儲存在mainbundle的乙個字典中,用下面 可以取出來 nsdictionary infodict nsbundle mainbundle infodictionary nsstring versionnum infodict obj...
iOS 獲取裝置資訊
ios 獲取裝置資訊 獲取裝置資訊,不囉嗦,直接上 uidevice idfa add adsupport.framework define kdeviceidfa asidentifiermanager sharedmanager advertisingidentifier uuidstring ...