enum
enum

Reputation: 51

C# Netfwtypelib - add more than 1 remote address?

How to add more than 1 ip address to firewall rule with C#?

I tried to do things like:

rule.RemoteAddresses += "127.0.0.1";
rule.RemoteAddresses += "129.0.0.1";

or

List<string> list = new List<string>();
list.Add("127.0.0.1");
list.Add("129.0.0.1");
rule.RemoteAddresses = list.ToString();

but it will give you only exception.

Upvotes: 0

Views: 938

Answers (1)

enum
enum

Reputation: 51

i found it on Programmatically add IP to Server 2008 firewall rule

Working code:

INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
var rule = firewallPolicy.Rules.Item("Block Bad IP Addresses");

rule.RemoteAddresses += "," + ip;

Upvotes: 3

Related Questions