[英]Server IP address of wifi in iphone device
我想獲取iPhone設備中wifi的服務器IP地址。 我不想要iphone設備中wifi的設備ipaddress ...如果有任何API可以獲取iphone中wifi的服務器IP地址。請參考並共享那些鏈接...
例如 我的iPhone已連接到XYZ wifi。 是否可以獲取提供WIFI接入的服務器的實時IP地址?
使用Objective-C方法將WiFi連接的IP地址作為NSString檢索。
- (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;
}
如果這對您不起作用,則可能還需要在類實現的頂部包括以下C標頭
#include <ifaddrs.h>
#include <arpa/inet.h>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.