Few days ago, I began work on a Windows Firewall component in Delphi, and my work is currently up on Github.
The name of the unit containing the Windows Firewall component is called System.Win.Firewall, and the component is called TWindowsFirewall. The example project has 2 functions. 1 function lists all the firewall rules, and the other creates a rule, blocking a list of addresses.
The function that lists all the firewall rules, look like so:
procedure
ShowRule(
const
ARule: TWindowsFirewall
.
TWindowsFirewallRule);
begin
WriteLn
(
'Name: '
, ARule
Name);
'Action: '
Action
ToString);
'Description: '
Description);
'Direction: '
Direction
'Enabled: '
Enabled);
'Profile: '
Profile
'Interface Types: '
InterfaceTypes
'-----------------------------------'
);
end
;
EnumRules;
var
LFirewall: TWindowsFirewall;
LRule: TWindowsFirewall
TWindowsFirewallRule;
LRuleName, LInterface:
string
LFirewall := TWindowsFirewall
Create;
try
for
LRuleName
in
TArray<
>.Create(
'Doesn'
't exist'
,
'Test rule using TWindowsFirewall'
)
do
if
LFirewall
Rules
FindRule(LRuleName)
then
LRule := LFirewall
Rules[LRuleName];
ShowRule(LRule);
LRule
Free;
finally
Feel free to check out the repository, or if you're interested in extending/enhancing the component further, or collaborate with me.