I am trying to get the IP Address using NSHost
. With the NSHost
object I can use the addresses method to access an array of objects one of which is the IP Address. I fear though that the IP Address may change position in the array from one machine to the other. Is there a way to access this information in a universal way?
There was an attempt to answer this question in a previous post, but as you can see it falls short.
Here is my code:
+(NSString *) ipAddress {
NSHost * h = [[[NSHost currentHost] addresses] objectAtIndex:1];
return h ;
}
You can create a category on NSHost and do something like this:
.h
.m
This works really fast and well. If you need other info or to monitor then use System Configuration framework.