![]() |
UPnP Port Forwarding
Hallo zusammen,
ich versuche per UPnP einen Port bei meinem Router (FritzBox) freizugeben. Hierzu habe ich die UPnPNAT TypeLib importiert und versuche nun über diese Schnittstelle an die Port Mappings zu gelangen:
Delphi-Quellcode:
Leider ist StaticPortMappingCollection immer nil.
var
NAT: TUPnPNAT; begin NAT := TUPnPNAT.Create(nil); NAT.StaticPortMappingCollection; Im Internet habe ich leider wenig Informationen gefunden. Dort heißt es nur, dass der Wert nil ist, wenn der Router kein UPnP unterstüzt. Allerdings habe ich alles in der Richtung aktiviert und mit einem (Java) Tool funktioniert auch alles tadellos. Was mache ich also falsch? Ich vermute, dass das diese UPnPNAT Klasse leider zu einem Standarddevice connected, welches nicht mein Router ist. Die Klasse beinhaltet auch eine ConnectTo() Methode, allerdings weiß ich nicht, wie ich alle vorhandenen UPnP Geräte auflisten kann, oder ob das überhaupt die Fehlerursache ist. Viele Grüße Zacherl |
AW: UPnP Port Forwarding
Das Verhalten riecht ein wenig nach Interfaces :)
Schon mal geschaut ob es da ein passendes gibt? Bei SO gibt es was zu dem Thema ![]() |
AW: UPnP Port Forwarding
Jap diesen Post hatte ich auch gefunden, aber dort heißt es auch nur wieder:
Zitat:
|
AW: UPnP Port Forwarding
:duck: push
|
AW: UPnP Port Forwarding
Ich hab mich auch gerade eben damit befasst und an diversen Beispielcodes, die im Internet so dazu zu finden sind, rumgebastelt.. Diese Lösung funktioniert bei mir:
Delphi-Quellcode:
möglicher Aufruf:
unit aphtonUPnP;
interface uses Windows, ActiveX, oleAuto, Variants, SysUtils; type TUPnP_PortMapTable = class public class function add(const active: Boolean; const extPort, intPort: DWORD; const ip, proto, desc: String): Boolean; class function remove(const extPort: DWORD; const proto: String): Boolean; end; implementation class function TUPnP_PortMapTable.add(const active: Boolean; const extPort, intPort: DWORD; const ip, proto, desc: String): Boolean; var n, p: Variant; Begin Result := False; try n := CreateOleObject('HNetCfg.NATUPnP'); p := n.StaticPortMappingCollection; if not VarIsClear(p) then begin p.Add(extPort, UpperCase(proto), intPort, ip, active, desc); Result := True; end; except // on e: exception do showmessage(e.Message); end; end; class function TUPnP_PortMapTable.remove(const extPort: DWORD; const proto: String): Boolean; var n, p: Variant; Begin Result := False; try n := CreateOleObject('HNetCfg.NATUPnP'); p := n.StaticPortMappingCollection; if not VarIsClear(p) then Result := p.Remove(extPort, UpperCase(proto)) = S_OK; except // on e: exception do showmessage(e.Message); end; end; end.
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin if not TUPnP_PortMapTable.remove(1234, 'tcp') then showmessage('remove failed'); if not TUPnP_PortMapTable.add(true, 1234, 4444, '192.168.1.4', 'TCP', 'test') then showmessage('add failed'); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:44 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