Preguntando a chatgpt:
Código Delphi
[-]uses
ComObj;
procedure AllowOnlySpecificIPs(const AllowedIPs: TStringList);
var
fwPolicy2: OleVariant;
fwRules: OleVariant;
fwRule: OleVariant;
i: Integer;
begin
fwPolicy2 := CreateOleObject('HNetCfg.FwPolicy2');
fwRules := fwPolicy2.Rules;
fwRules.RemoveAll;
for i := 0 to AllowedIPs.Count - 1 do
begin
fwRule := CreateOleObject('HNetCfg.FWRule');
fwRule.Action := NET_FW_ACTION_ALLOW;
fwRule.Description := 'Permitir tráfico solo desde ' + AllowedIPs[i];
fwRule.Direction := NET_FW_RULE_DIR_IN;
fwRule.Enabled := True;
fwRule.InterfaceTypes := 'All';
fwRule.RemoteAddresses := AllowedIPs[i];
fwRules.Add(fwRule);
end;
end;
Y así añades las IP permitidas:
Código Delphi
[-]var
AllowedIPs: TStringList;
begin
AllowedIPs := TStringList.Create;
try
AllowedIPs.Add('Dirección_IP_1');
AllowedIPs.Add('Dirección_IP_2');
AllowOnlySpecificIPs(AllowedIPs);
finally
AllowedIPs.Free;
end;
end;