This is called a firewall you're attempting to write. Unless you know the Windows network stack, you'll find this extremely difficult to implement.
For testing, you could pass this information in through the services OnStart method arguments. It works just like you wrote. The arguments would be passed in as a couple of strings in an array.
For a production application, a firewall config is usually stored somewhere else, like an encrypted entry in the Registry or a config file.