[Pythonmac-SIG] Mac OS X native DNS lookups
Nicholas Riley
njriley at illinois.edu
Wed Nov 3 03:32:43 CET 2010
On Wed, Nov 03, 2010 at 12:16:34PM +1000, James Mills wrote:
> The problem with this (that we have) is that when/if the dns servers change
> (example: unplug the wire, turn on the wireless) this method of resolving names
> isn't able to tell that the dns servers have changed quickly enough.
>
> On Windows we've solved this by hooking into win32 calls (windns I believe)
> and using ctypes.
>
> We're after something similar on the Mac OS X platform ideally...
socket.* *does* use the Mac native resolution mechanism. What you're
running into is that they cache too aggressively; I've noticed this
myself especially on 10.6.
Executing 'dscacheutil -flushcache' should help; it doesn't require
any privileges. You can use the SystemConfiguration framework to
watch for DNS changes (State:/Network/Global/DNS). It's wrapped by
PyObjC. At least on my 10.5 Mac here there's a demo script in
/Developer/Examples/Python/PyObjC/SystemConfiguration/CallbackDemo/callbacks.py
which registers for dynamic store notifications. You could also talk
to scutil if you wanted; it's also got the ability to register for
notifications:
% scutil
> n.add State:/Network/Global/DNS
> n.watch
> notification callback (store address = 0x103730).
changed key [0] = State:/Network/Global/DNS
--
Nicholas Riley <njriley at illinois.edu>
More information about the Pythonmac-SIG
mailing list