[Pythonmac-SIG] How to set the hosts file using Python

Jack Jansen Jack.Jansen at cwi.nl
Thu Dec 11 15:42:04 EST 2003


On 11-dec-03, at 18:50, RANDY BURNS wrote:

> I have a small  application that runs on both win32 and MaxOS 10.x 
> that creates an appropriate
> hosts file on demand(I'm doing this because I need folks to review a 
> web page on development, test or production servers).
> I see how to set the host file manually on the mac. Does anyone have 
> an idea how this might be done through a python script?
> Thanks!
>  
> http://docs.info.apple.com/article.html?artnum=75085

Note that that document is about MacOS9, not about MacOSX!

The hosts file exists on MacOSX (in /etc/hosts, the usual location for 
Unix) but there isn't really all that much in it by default. But if you 
want to add entries there to make a specific DNS address go to a 
specific IP address I think it will work, although I'm not sure in what 
order the nameserver and the /etc/hosts files are searched, so you may 
not be able to override things.

Note that you probably have to run as superuser to write /etc/hosts.
--
Jack Jansen, <Jack.Jansen at cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman




More information about the Pythonmac-SIG mailing list