I figured something out that succeeded in making the hostname constant, and it allows me to run the socket programs without error. I'm posting what I did for future seekers. This is for mac os 10.4.7:
1) In System Preferences>Sharing, there is a name entered there: Computer Name: John Smiths computer But underneath that is this text: Other computers on your local subnet can access your computer at John-Smiths-computer.local Copy the name John-Smiths-computer.local exactly as written. Notice the added dashes and the extension. If you want, you can change the name by entering something else in the text box to the right of "Computer Name:". Then if you click outside the text box elsewhere to move the focus away from the text box, the text underneath the text box will update with the new name, and that is the exact name you need to use for step 2. 2) In the file /etc/hostconfig, at the bottom I added the line: HOSTNAME=John-Smiths-computer.local The name entered there has to be the exact same name as the name in step 1. The hostconfig file is read only unless you are logged in using the root account(which you are never supposed to do). In any case, you can use the sudo command to momentarily become the superuser, which will enable you to edit hostcofig. If you are logged in as the root account, then you'll be able to edit hostconfig without having to use the sudo command. I used the cd command to change directories to /etc: $ cd /etc Then I used vi to edit the hostconfig file $ sudo vi hostconfig Hold your breath because you don't want to mess anything up when you have root privileges, although I don't think you can get in much trouble while editing a text file. Then save the file. 3) Restart your computer. I think there must be a way to reload the hostconfig file with out having to restart, but I couldn't figure out which command to use to accomplish that. After restarting, the hostname part of my prompt in Terminal stayed constant whether I was connected to the internet or not. And I could run the socket programs in my original post using gethostname()--whether I was connected to the internet or not. -- http://mail.python.org/mailman/listinfo/python-list