How to get all available hostnames and associated IP addresses on LAN using Obj C on Mac OS X?
I have a requirement to get the list of IP addresses of all the machines connected to LAN. I created an NSHost object and used it to get addresses of current host and it worked fine. But I need to get addresses of all other ho开发者_如何学编程sts on the network. Any helpful answer would be appreciable. Thanks in advance.
my snippet:
NSHost* host = [NSHost currentHost];
NSString* myIPAddress = [NSString stringWithFormat:
[[host addresses] objectAtIndex:1]];
executing this gave myIPAddress as 192.168.1.202 which is correct.
That's not necessarily knowable, and depends on collusion with the other hosts. You might consider determining your broadcast address (e.g. 192.168.1.255), sending an ICMP echo request and then enumerating the responses: but a system that doesn't respond to the request won't show up. Similar problems are apparent when using responses to any other request: port scans or mDNS registrations.
精彩评论