Ios 如何从连接到我的wifi的IP地址或MacAddress获取主机名

Ios 如何从连接到我的wifi的IP地址或MacAddress获取主机名,ios,network-programming,hostname,local-network,Ios,Network Programming,Hostname,Local Network,我想获得连接到我的wifi路由器的设备的mac地址、IP地址、主机名、设备名和品牌名。除主机名外,我将获得所有这些 我尝试过MMLAnscan、AFNetworking、LANScanMaster等,它将为我提供除主机名以外的所有详细信息 +(NSString *)getHostFromIPAddress:(NSString*)ipAddress { struct addrinfo *result = NULL; struct addrinfo hints; memse

我想获得连接到我的wifi路由器的设备的mac地址、IP地址、主机名、设备名和品牌名。除主机名外,我将获得所有这些

我尝试过MMLAnscan、AFNetworking、LANScanMaster等,它将为我提供除主机名以外的所有详细信息

+(NSString *)getHostFromIPAddress:(NSString*)ipAddress {
    struct addrinfo *result = NULL;
    struct addrinfo hints;

    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = AI_NUMERICHOST;
    hints.ai_family = PF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = 0;

    //"www.kame.net", "http"
    int errorStatus = getaddrinfo([ipAddress cStringUsingEncoding:NSUTF8StringEncoding], NULL, &hints, &result);
    //NSUTF8StringEncoding instead of NSASCIIStringEncoding
    if (errorStatus != 0) {
        return nil;
    }

    CFDataRef addressRef = CFDataCreate(NULL, (UInt8 *)result->ai_addr, result->ai_addrlen);
    if (addressRef == nil) {
        return nil;
    }
    freeaddrinfo(result);

    CFHostRef hostRef = CFHostCreateWithAddress(kCFAllocatorDefault, addressRef);
    if (hostRef == nil) {
        return nil;
    }
    CFRelease(addressRef);

    BOOL succeeded = CFHostStartInfoResolution(hostRef, kCFHostNames, NULL);
    if (!succeeded) {
        return nil;
    }

    NSMutableArray *hostnames = [NSMutableArray array];

    CFArrayRef hostnamesRef = CFHostGetNames(hostRef, NULL);
    for (int currentIndex = 0; currentIndex < [(__bridge NSArray *)hostnamesRef count]; currentIndex++) {
        [hostnames addObject:[(__bridge NSArray *)hostnamesRef objectAtIndex:currentIndex]];
        NSLog(@"hostt:%@",hostnames);
    }
    NSLog(@"hostname:%@",hostnames[0]);
    return hostnames[0];
}
+(NSString*)getHostFromIPAddress:(NSString*)ipAddress{
struct addrinfo*result=NULL;
结构addrinfo提示;
memset(&hints,0,sizeof(hints));
hits.ai_flags=ai_numericost;
hits.ai_family=PF_unsec;
hits.ai_socktype=SOCK_流;
hits.ai_协议=0;
//“www.kame.net”、“http”
int errorStatus=getaddrinfo([ipAddress cStringUsingEncoding:NSUTF8StringEncoding]、NULL、提示和结果);
//NSUTF8StringEncoding代替NSASCIIStringEncoding
如果(错误状态!=0){
返回零;
}
CFDataRef addressRef=CFDataCreate(NULL,(UInt8*)result->ai_addr,result->ai_addrlen);
如果(addressRef==nil){
返回零;
}
freeaddrinfo(结果);
CFHostRef hostRef=CFHostCreateWithAddress(kCFAllocatorDefault,addressRef);
如果(hostRef==nil){
返回零;
}
CFRelease(addressRef);
BOOL successed=CFHostStartInfoResolution(hostRef,kCFHostNames,NULL);
如果(!成功){
返回零;
}
NSMutableArray*主机名=[NSMutableArray];
CFArrayRef hostnamesRef=CFHostGetNames(hostRef,NULL);
对于(int currentIndex=0;currentIndex<[(\uu桥NSArray*)主机名称参考计数];currentIndex++){
[hostnames addObject:[(_桥NSArray*)hostnamesRef objectAtIndex:currentIndex];
NSLog(@“主机:%@”,主机名);
}
NSLog(@“主机名:%@”,主机名[0]);
返回主机名[0];
}
我想要连接到我的wifi的设备的主机名