How universal is UPnP? I use the following with success to create a
connection and get external address on a system using XP Internet connection
sharing. Does it work with a LinkSys router or other commonly used home
setups?
Add reference to NATUPNPLib.dll
using NATUPNPLib;
IPEndPoint external;
IPEndPoint local;
public void PrepareForNAT( int publicPort )
{
NATUPNPLib.UPnPNATClass nat = new NATUPNPLib.UPnPNATClass();
IStaticPortMappingCollection spmc = nat.StaticPortMappingCollection;
// make sure not there
try
{
spmc.Remove( local.Port, "TCP" );
}
catch( System.IO.FileNotFoundException )
{
// ok
}
IStaticPortMapping spm = spmc.Add( publicPort, "TCP", local.Port,
"MyLocalName", true, "id for display" );
external = new IPEndPoint( IPAddress.Parse( spm.ExternalIPAddress ),
spm.External Port );
}
// worth having a Dispose method to do a spmc.Remove( local.Port, "TCP" ) to
clean up...
You can check the results by right clicking internet connection, choosing
properties, and pressing the settings button. It takes a bit of time to
load.
"Thomas Tomiczek [MVP]" <t.********@thona-consulting.com> wrote in message
news:uv****************@tk2msftngp13.phx.gbl...
A third possibility (if the router supports so) ould be using UPnP to
query for the outside IP address.
"Demetri" <an*******@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com... How do I find out what the network IP address is?
For example if I have a cable modem with 68.57.200.50 as the IP
address and the linksys router assigns PC's on the network 192.168.1.1 how do I
find out that the address is 68.57.200.50 running my code on the PC with the
IP address assigned to it by the router of 192.168.1.1 ?
Make sense what I'm asking? I like using WMI but if there is another
way I'm willing to listen.