AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Netzwerkports auffinden und sperren ?????
Thema durchsuchen
Ansicht
Themen-Optionen

Netzwerkports auffinden und sperren ?????

Offene Frage von "EDatabaseError"
Ein Thema von EDatabaseError · begonnen am 7. Nov 2005 · letzter Beitrag vom 7. Nov 2005
Antwort Antwort
Seite 2 von 2     12   
EDatabaseError

Registriert seit: 11. Mai 2005
Ort: Göppingen
1.238 Beiträge
 
Delphi 2007 Professional
 
#11

Re: Netzwerkports auffinden und sperren ?????

  Alt 7. Nov 2005, 14:32
gut schau ich mir mal an
Tobias
It's not a bug, it's a feature.
  Mit Zitat antworten Zitat
Benutzerbild von x000x
x000x

Registriert seit: 21. Jan 2004
Ort: Bei Hamburg
308 Beiträge
 
Delphi XE2 Professional
 
#12

Re: Netzwerkports auffinden und sperren ?????

  Alt 7. Nov 2005, 20:49
Moin moin,

wenn du wirklich alles sperren willst, dann ist es sogar relativ einfach. Es reicht, per
API ein Interface zu erstellen, welches per Default alles dropt...

Wenn du mehr zum Thema wissen willst, suche mal über Google nach folgenden
Units: fltdefs.pas, iphlpapi.pas bzw. bei MSDN MSDN-Library durchsuchenPacket Filtering Reference

Du hast oben irgendwo nach einem Beispiel gefragt, hier ist ein ganz simples...

Delphi-Quellcode:
{
Aufruf:
  InstallFW('192.168.0.2');

und zum schluss:
  RemoveFW;
}

unit DropAllU;

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.
Peter
-= Gruss Peter =-
-= alias x000x =-
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz