0

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

RJ168
  • 1,006
  • 2
  • 12
  • 22

1 Answers1

1

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.

Community
  • 1
  • 1
dgatwood
  • 10,129
  • 1
  • 28
  • 49
  • Just to add one minor nit to my answer. There is one situation where mDNS *might* know about your router. If the router happens to be an Airport Base Station or Time Capsule, mDNS *may* use that device as a sleep proxy server. The fact that this happens to be the same device as the router is entirely coincidental, though, and that is not guaranteed. A Mac with sleep disabled or an Apple TV can also act as the SPS. As far as I know, there's no way to find out what device is being used as the SPS except by reading through the logs. Either way, mDNS doesn't care that it's a router, though. – dgatwood Aug 14 '16 at 04:56