![]() |
Firewall nur mit bestimmtem/n port/ports
hey leutz,
Ihr hab ich das DropAllU von x000x:
Delphi-Quellcode:
Dies schliest ALLE ports bei der InstallFW() function doch ich will nur einen bestimmten port schliesen. (8484)
unit DropAllU;
{ Aufruf: InstallFW('192.168.0.2'); und zum schluss: RemoveFW; } interface procedure InstallFW(MyIP: String); procedure RemoveFW; implementation uses Windows; const IPHLPAPI = 'IPHLPAPI.DLL'; type PFFORWARD_ACTION = Integer; PPFFORWARD_ACTION = ^PPFFORWARD_ACTION; // INTERFACE_HANDLE = Pointer; // PFADDRESSTYPE = Integer; PPFADDRESSTYPE = ^PFADDRESSTYPE; // TByteArray = Array [0..Pred(MaxInt)] of Byte; PByteArray = ^TByteArray; TIpBytes = Array [0..3] of Byte; const PF_ACTION_DROP = 1; const PF_IPV4 = 0; function PfCreateInterface( dwName: DWORD; inAction: PFFORWARD_ACTION; outAction: PFFORWARD_ACTION; bUseLog: BOOL; bMustBeUnique: BOOL; var ppInterface: INTERFACE_HANDLE): DWORD; stdcall; external IPHLPAPI name '_PfCreateInterface@24'; function PfDeleteInterface( pInterface: INTERFACE_HANDLE): DWORD; stdcall; external IPHLPAPI name '_PfDeleteInterface@4'; function PfBindInterfaceToIPAddress( pInterface: INTERFACE_HANDLE; pfatLinkType: PFADDRESSTYPE; IPAddress: PByteArray): DWORD; stdcall; external IPHLPAPI name '_PfBindInterfaceToIPAddress@12'; function PfUnBindInterface( pInterface: INTERFACE_HANDLE): DWORD; stdcall; external IPHLPAPI name '_PfUnBindInterface@4'; var Handle_Interface : INTERFACE_HANDLE = nil; function StrToInt(S: PChar): Integer; begin Result := 0; if S = '' then Exit; while S^ in ['0'..'9'] do begin Result := Result * 10 + Integer(S^) - Integer('0'); Inc( S ); end; end; function StrToIpBytes( IpStr: String ): TIpBytes; var N : Integer; begin N := 0; while Pos('.', IpStr)>0 do begin Result[N] := StrToInt(@Copy(IpStr, 1, Pos('.', IpStr) - 1)[1]); Delete(IpStr, 1, Pos('.', IpStr)); Inc(N); end; Result[N] := StrToInt(@IpStr[1]); end; procedure InstallFW(MyIP: String); var IpLocal : TIpBytes; begin if (MyIP <> '') and Not Assigned(Handle_Interface) then begin FillChar(IpLocal, 4, #0); IpLocal := StrToIpBytes(MyIP); PfCreateInterface(0, PF_ACTION_DROP, PF_ACTION_DROP, False, False, Handle_Interface); PfBindInterfaceToIPAddress(Handle_Interface, PF_IPV4, @ipLocal); end; end; procedure RemoveFW; begin if Assigned(Handle_Interface) then begin PfUnBindInterface(Handle_Interface); PfDeleteInterface(Handle_Interface); Handle_Interface := nil; end; end; end. Doch wo steht das hier? Oder muss man es dann ganz umschreiben? |
Re: Firewall nur mit bestimmtem/n port/ports
|
Re: Firewall nur mit bestimmtem/n port/ports
hmm ich hab mir das jetzt mal durchgelesen bei
PfCreateInterface() doch hat mich jetzt nicht wirklich weitergebracht. Es droppt ja alle alles. Bitte hilfe. :?: |
Re: Firewall nur mit bestimmtem/n port/ports
{bump] hmm Kann das sein das es garnicht möglich ist? Also ich bekomms nich gebacken :gruebel: [/bump]
|
Re: Firewall nur mit bestimmtem/n port/ports
Moin moin,
doch es ist möglich... PfCreateInterface mit PF_ACTION_DROP als 2 und 3 Parameter sagt nur, dass alle Pakete die reinkommen und alle die die rausgehen und keiner Filterregel entsprechen, geblockt werden. Du musst einfach noch Filter hinzufügen. Schau dir die funktion PfAddFiltersToInterface an... Den link zur Doku hast du ja schon.
Delphi-Quellcode:
function PfAddFiltersToInterface(
ih: INTERFACE_HANDLE; cInFilters: DWORD; pfiltIn: PPF_FILTER_DESCRIPTOR; cOutFilters: DWORD; pfiltOut: PPF_FILTER_DESCRIPTOR; pfHandle: PFILTER_HANDLE): DWORD; stdcall; external IPHLPAPI name '_PfAddFiltersToInterface@24'; function PfRemoveFiltersFromInterface( ih: INTERFACE_HANDLE; cInFilters: DWORD; pfiltIn: PPF_FILTER_DESCRIPTOR; cOutFilters: DWORD; pfiltOut: PPF_FILTER_DESCRIPTOR): DWORD; stdcall; external IPHLPAPI name '_PfRemoveFiltersFromInterface@20'; |
Re: Firewall nur mit bestimmtem/n port/ports
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:37 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz