[DUG] UPnP port forwarding
Ross Levis
ross at stationplaylist.com
Wed Sep 7 18:09:33 NZST 2011
I hope you are right. I'll check this out and let you know.
I guess this means the UPnP changes are lost when the router is reset.
Cheers.
From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Stefan Mueller
Sent: Wednesday, 7 September 2011 5:30 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] UPnP port forwarding
My router interface actually doesn't show any upnp forwards .. it shows the
usual static port forwarding config screen, but that is configured/managed
separately from what is set with upnp.
For me, the only way to see upnp forwards is by using the script I emailed
before (no need to convert to delphi, just save it as *.vbs script file and
run it!). Maybe other routers are better, but mine only has an "upnp
enabled" checkbox and that is all there is for managing upnp settings.
The only way to test it is by having something listening on the port
(accepting incoming connections) and then using a website like
http://www.canyouseeme.org/ to check if a connection to that port from
external can be made or not (needs to be tested from external, can't test
from within your own network just by using your external wan-address . and
don't forget to configure or switch off your firewall!).
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: Wednesday, September 07, 2011 1:38 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] UPnP port forwarding
I am using my IP, in fact using an Indy function to get that automatically,
and it is correct.
I assume the required test to check if it's worked is to load the router
configuration page and see if the added port appears in the list of
forwarded ports, and it doesn't. It's a Linksys WAG320N.
I thought of converting the VB code below to see if it is communicating with
the router, so I may have to do that.
Ross.
From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Stefan Mueller
Sent: Wednesday, 7 September 2011 6:11 a.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] UPnP port forwarding
Gave it a quick test in delphi .. Your code actually works fine for me. I
ran a simple chat server I did a couple of weeks ago (a html websocket
server) on my computer and checked with the website at
http://www.canyouseeme.org/ to see if external computers can connect to me.
No idea what the problem is on your end, but I think it's your router, not
your code (unless you pass in the wrong ip address, you pass in your local
one, right? Like 192.168.1.3 for example?!) .. Or did you forget to
configure your firewall (easiest is to just shut it down for testing - if
you are behind a NAT router then you don't really need a firewall so that
shouldn't be a problem to run a couple of tests). . or did you try to open a
port that has already static port forwarding in your router to another
computer?
Did you check your router for open upnp connections? Following script lists
them:
Set theNatter = CreateObject( "HNetCfg.NATUPnP")
Dim mappingPorts
Set mappingPorts = theNatter.StaticPortMappingCollection
MsgBox("Total number of ports is " & mappingPorts.Count)
for each mappingPort in mappingPorts
MsgBox( mappingPort.Description & " " & mappingPort.ExternalPort & " " &
mappingPort.Protocol & " " & mappingPort.InternalPort)
Next
(save as *.vbs file, run it with cscript.exe)
As far as I am concerned that code you wrote works perfectly fine.
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: Tuesday, September 06, 2011 9:00 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] UPnP port forwarding
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/650cc28d/attachment-0001.html
More information about the Delphi
mailing list