| - (NSString *)getIPAddress { | |
| Boolean result; | |
| CFHostRef hostRef; | |
| CFArrayRef addresses; | |
| NSString *hostname = @"www.google.com"; /*change to required host name */ | |
| NSString *ipAddress = @""; | |
| hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname); | |
| if (hostRef) { | |
| result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); | |
| if (result == TRUE) { | |
| addresses = CFHostGetAddressing(hostRef, &result); | |
| } | |
| } | |
| if (result == TRUE) { | |
| CFIndex index = 0; | |
| CFDataRef ref = (CFDataRef) CFArrayGetValueAtIndex(addresses, index); | |
| struct sockaddr_in* remoteAddr; | |
| char *ip_address; | |
| remoteAddr = (struct sockaddr_in*) CFDataGetBytePtr(ref); | |
| if (remoteAddr != NULL) { | |
| ip_address = inet_ntoa(remoteAddr->sin_addr); | |
| } | |
| ipAddress = [NSString stringWithCString:ip_address encoding:NSUTF8StringEncoding]; | |
| } | |
| return ipAddress; | |
| } |
Friday, 24 August 2018
iOS: How to get the IP Address from Host name Objective C
Subscribe to:
Comments (Atom)
Setting Up Multiple App Targets in Xcode from a Single Codebase
To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps b...
-
if u want to open in same window - ( WKWebView *) webView :( WKWebView *) webView createWebViewWithConfiguration :( WKWebViewConfigurat...
-
To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps b...
-
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"prefs:root=General&path=Network"]]; List of curre...