Re: [Pythonmac-SIG] Mac OS X native DNS lookups
On Wed, Nov 03, 2010 at 12:38:41PM +1000, James Mills wrote: > On Wed, Nov 3, 2010 at 12:32 PM, Nicholas Riley wrote: > > At least on my 10.5 Mac here there's a demo script in > > /Developer/Examples/Python/PyObjC/SystemConfiguration/CallbackDemo/callbacks.py > > I don't seem to have a "Python" directory in /Developer/Examples/ on > my Mac (10.6.4) It's distributed with PyObjC - you can also get it from http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-framework-SystemConfiguration/Examples/CallbackDemo/ -- Nicholas Riley ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Re: [Pythonmac-SIG] Mac OS X native DNS lookups
On Wed, Nov 3, 2010 at 12:32 PM, Nicholas Riley wrote: > At least on my 10.5 Mac here there's a demo script in > /Developer/Examples/Python/PyObjC/SystemConfiguration/CallbackDemo/callbacks.py I don't seem to have a "Python" directory in /Developer/Examples/ on my Mac (10.6.4) cheers James -- -- James Mills -- -- "Problems are solved by method" ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Re: [Pythonmac-SIG] Mac OS X native DNS lookups
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 ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Re: [Pythonmac-SIG] Mac OS X native DNS lookups
On Wed, Nov 3, 2010 at 11:47 AM, Nicholas Riley wrote: > Try socket.gethostbyname for IPv4-only or socket.getaddrinfo for > IPv4/IPv6. For example: > import socket socket.gethostbyname('mary.local') > '192.168.71.1' socket.getaddrinfo('bookworm.griley.members.mac.com', None, socket.AF_INET6, socket.SOCK_STREAM) > [(30, 1, 6, '', ('fda1:5f1b:430f:37cc:214:51ff:fe0b:d94', 0, 0, 0))] 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... cheers James -- -- James Mills -- -- "Problems are solved by method" ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Re: [Pythonmac-SIG] Mac OS X native DNS lookups
On Wed, Nov 03, 2010 at 11:25:49AM +1000, James Mills wrote: > Been looking around the web for how you might resolve hostnames on Mac > OS X using OS X's sys calls to do so. > > Can anyone shed any light on this ? Try socket.gethostbyname for IPv4-only or socket.getaddrinfo for IPv4/IPv6. For example: >>> import socket >>> socket.gethostbyname('mary.local') '192.168.71.1' >>> socket.getaddrinfo('bookworm.griley.members.mac.com', None, >>> socket.AF_INET6, socket.SOCK_STREAM) [(30, 1, 6, '', ('fda1:5f1b:430f:37cc:214:51ff:fe0b:d94', 0, 0, 0))] Check the Python docs (http://docs.python.org/library/socket.html) for information on the tuples returned by getaddrinfo. -- Nicholas Riley ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
[Pythonmac-SIG] Mac OS X native DNS lookups
Hi, Been looking around the web for how you might resolve hostnames on Mac OS X using OS X's sys calls to do so. Can anyone shed any light on this ? cheers James -- -- James Mills -- -- "Problems are solved by method" ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG