tags:

views:

25

answers:

1

How do you programmatically add a new entry to the Hosts file in Mac?

For example on Windows, you just open up a StreamWriter and output to the Hosts file. How do you do this on a Mac?

+1  A: 

The hosts file is at

/etc/hosts

so you can add to it by just writing to it. But you should never delete the first few lines corresponding to the local host. Also, it's only accessible with the root privilege.

Yuji
But how do I programmatically add the lines to the Hosts file?
Romulus
It is a text file. You can use whatever means to do that.
Yuji