[DUG] UPnP port forwarding

Ross Levis ross at stationplaylist.com
Wed Sep 7 00:00:02 NZST 2011


I've condensed it to the following function, but it doesn't work.

 

procedure AddNatPortMapping(EntryName: string; Port: Cardinal; IP: string);

var

  NATUPnP, PortMapping: OleVariant;

begin

  NATUPnP := CreateOLEObject('HNetCfg.NATUPnP');

  PortMapping := NATUPnP.StaticPortMappingCollection;

  PortMapping.Add(Port, 'TCP', Port, IP, True, EntryName);

end;

 

I have confirmed that my router does support UPnP and is enabled.  Any
ideas?

 

But the delphi3000 code to add an application to the firewall does work.

 

Ross.

 

From: Ross Levis [mailto:ross at stationplaylist.com] 
Sent: Tuesday, 6 September 2011 10:11 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: RE: [DUG] UPnP port forwarding

 

I mistakenly thought the delphi3000 code was related to UPnP but it's only
opening the firewall, which will be necessary also.

 

The uPnP component mentioned doesn't even seem to have HNetCfg mentioned
anywhere in the source.

 

I have no experience working with OLE objects, assuming that is what
HNetCfg.NATUPnP is.  I'll try to translate some VB code from the knoxscape
site.  Does the following look correct?

 

var

  NATUPnP, PortMapping: OleVariant;

begin

  NATUPnP := CreateOLEObject('HNetCfg.NATUPnP');

  PortMapping := NATUPnP.StaticPortMappingCollection;

//We add a new port saying that externally accept from port 1024

//route to internal port 1024 on computer with IP 192.168.1.101

//Enabling the forward, and giving a name of the forward to be IRC

  PortMapping.Add(1024, "TCP", 1024, "192.168.1.101", TRUE, "IRC");

end;

 

 

Ross.

 

From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Stefan Mueller
Sent: Tuesday, 6 September 2011 2:19 a.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] UPnP port forwarding

 

Also found this one: http://www.whitebear.ch/upnp.htm

.. looks like somebody already made a nice Delphi-upnp component.

 

That upnp component looks like a bit of overkill though. Opening an upnp
port only requires a simple call to HNetCfg.NATUPnP .  and don't forget, you
also still need to open up your windows firewall . doing the upnp part on
the router is just half of the job of getting it working for your clients!
So, might as well use the HNetCfg com-api  as a convenient wrapper that does
everything . instead of the Delphi component. 

 


Regards,
Stefan

 

 

From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Stefan Mueller
Sent: Monday, September 05, 2011 11:05 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] UPnP port forwarding

 

Here are 3 links that should help:

 

http://www.delphi3000.com/articles/article_5021.asp?SK=

http://msdn.microsoft.com/en-us/library/aa366415.aspx

http://www.knoxscape.com/Upnp/NAT.htm

 

the HNetCfg com-api has all the necessary stuff in it to open and query upnp
devices. 

 

 


Kind Regards,
Stefan Mueller 
_______________________
R&D Manager
ORCL Toolbox LLP, Japan
http://www.orcl-toolbox.com <http://www.orcl-toolbox.com/>  

 

 

From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Ross Levis
Sent: Monday, September 05, 2011 7:30 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG] UPnP port forwarding

 

I'm increasingly being asked for help from my users for configuring port
forwarding in their routers.  My software has a couple of servers which need
to be accessed from the outside world if they wish to use some features.

 

I've heard UPnP will do this for them, and wondering if there is a simple
function someone has written for Delphi (D7) that can check if a specific
port number is already being forwarded and if not forward it.

 

Or otherwise a freeware app which can be run on a workstation to configure
any UPnP router.

 

Cheers,

Ross.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110907/c009108f/attachment.html 


More information about the Delphi mailing list