Search code examples
iosnetwork-programmingip-addressrouterbonjour

Fetching IP address of router to which iPhone is connected using Bonjour


I want to fetch the IP address of router to which my iPhone is currently connected via scanning the MDNS.

I think this can be achievable with Bonjour programming provided by Apple but can't get the proper implementation/guidance.

Can somebody help here with some reference code/documentations/url?

Thank you


Solution

  • mDNS and routing are completely unrelated systems; mDNS traffic doesn't even get routed.

    The only ways I know of to get routing data are to use either sysctl or a routing socket. And I think only the sysctl works in iOS (because you aren't root), but I'm not certain of that. See:

    Getting routing table on MACOSX (programmatically)

    And even that will get you only the router's local network address, which may not be what you're looking for, depending on your goals.