iphone - how to get the external ip in objective c -
I've seen to get some code will help me IP to connect with iphone. ; (NSString *) getIPAddress {NSString * n = @ "error" - But the problem is that he receives the IP 10.0.0.1 There is an article about obtaining external IP. Thanks Using the easiest way to get your internet IP address from code is. You can use the URL: or simply parse the return data and you have an external IP address.
: I find structure ifaddrs * interfaces A = NULL; Structure ifaddrs * temp_addr = NULL; Completed success = 0; // current interface to retrieve - return 0 Success Success = getifaddrs (& amp; Interface); If (success == 0) {// loop interface temp_addr interface via the linked list =; While (temp_addr = Zero!) {If (temp_addr-> saa_addr-> sa_family == AF_INET) {// Check the interface en0 which is the WiFi connection on the iPhone if ([[NSString stringWithUTF8String: temp_addr- & gt; ifa_name] isEqualToString: @ "en0"]) go NSString from {// C string address = [NSString stringWithUTF8String: inet_ntoa (((struct sockaddr_in *) temp_addr- & gt; ifa_addr) - & gt; sin_addr)]; }} Temp_addr = temp_addr- & gt; Ifa_next; }} // free memory Frifaders (interface); Return address; }
Comments
Post a Comment