Attached is an application called ExtIP. The original intent was to simply recover the External IP address used by a NAT router, but it ended up being much more. In order to use this program, your router must support Universal Plug and Play (UPnP), which most home routers do. However, not all routers support all functions, as evidenced by the descriptions below. Our own router does not support querying of the Mapping Collection, so some of the functions have not been fully tested.
If your router does not support UPnP, or it has not been turned on, executing any of the functions will produce a message stating "UPnPNAT not Found!".
If you know the external port number of an existing mapping, you can enter that number and recover the External IP address used on the WAN (Wide Area Network), as well as the Internal IP address and the Internal port. The older "GetIpAddrTable" is used to recover the Internal IP address, and uses the last address in the table. If you have more than one active Network Interface, it could produce a wrong result. It will also not produce a correct External IP address if you are using a double NAT configuration (not recommended). (tested)
If you would like to find out the External IP address and you do not know the port number used, you can leave the port number blank, and the program will scroll through the mapping collection and return the first one it finds. (not tested)
Clicking on the Get Ports button will scroll through the port mapping collection and add the External ports to the list box. Clicking on one of them will add it to the External Port box. (not tested)
You can also add a port mapping by entering an External Port number and clicking on the "Add Port Map" button. Normally the Internal Port number matches the External Port, and it will default to that, or you can add a different number. If the port mapping already exists, it will error out. (tested)
You should also be able to delete a port mapping, but our router does not support that function. (not tested)
This program does not support IPv6, because IPv6 does not require the use of NAT.
J.A. Coutts
Updated: Mar. 5, 2018 - See later post for details
Last edited by couttsj; Mar 5th, 2018 at 05:55 PM.
Interesting! I hadn't heard of the NATUPnP library before, but unfortunately it didn't work on my router even though uPnP's enabled. Do you know if this is using NAT-PMP to do what it's doing? If so I know mine doesn't have it. There was a time in my commercial app where I wanted to get the external IP for each computer on the network. I researched various methods like NAT-PMP, tracerouting, etc. and ended up having to revert to just visiting one of those "what's my IP" sites and pulling the IP from there. First I used a list of those sites in case one was down, but ended up getting my own domain/site that just spit out the external IP back to the user. I do wish there was a better way to get the external IP that works everywhere without needing to contact a website.
Interesting! I hadn't heard of the NATUPnP library before, but unfortunately it didn't work on my router even though uPnP's enabled. Do you know if this is using NAT-PMP to do what it's doing? If so I know mine doesn't have it. There was a time in my commercial app where I wanted to get the external IP for each computer on the network. I researched various methods like NAT-PMP, tracerouting, etc. and ended up having to revert to just visiting one of those "what's my IP" sites and pulling the IP from there. First I used a list of those sites in case one was down, but ended up getting my own domain/site that just spit out the external IP back to the user. I do wish there was a better way to get the external IP that works everywhere without needing to contact a website.
You could always use my Port Tester: http://www.vbforums.com/showthread.p...B6-Port-Tester
It basically does the same thing as a Web page without all the bells and whistles. It does however require the server to be outside of your network.
Don't you just hate it when that happens dilettante? I will make sure to search the forums hard before ever posting a project.
So if it's not NAT-PMP and really is just uPnP, I'm not sure why I can't get either app working. I'm really interested in getting the external IP more than anything, without having to contact an outside website and UPnP is enabled. I'm using a modern ASUS router with the Merlin firmware. UPnP is definitely enabled as I've tested it using a little UPnP discovery sample I been working on. I get back all kinds of info from it using that. I have to be missing something. Maybe there's another option in the router related to this I don't have enabled?
When I click the button "Get Ports", I get the following error:
Run-time error '-2147220984 (80040208)':
Method 'Item' of object 'IStaticPortMappingCollection' failed
Error code line:
Code:
Private Sub cmdPorts_Click()
Dim PortMap As NATUPNPLib.IStaticPortMapping
Dim Protocol As String
Dim Port As Long
Protocol = txtProtocol.Text
If Protocol <> "TCP" Or Protocol <> "UDP" Then Protocol = "TCP"
'Check to make sure NAT UPnP is active
If Mappings Is Nothing Then
MsgBox "UPnPNAT not Found!", vbExclamation
Exit Sub
End If
'Find number of mappings
If Mappings.Count > 0 Then
For Each PortMap In Mappings
Port = Mappings(PortMap.InternalPort, Protocol).InternalPort
lstPorts.AddItem CStr(Port)
Next
Else
MsgBox "No mappings found!" & vbCrLf & "Router may not supply these.", vbExclamation
End If
End Sub
ExtIP was simplified by removing one of the command buttons. The "Map Port" button now serves the function of both "Get IP" and "Add Port Map". This was accomplished by intercepting the Error 0x800700AA, which basically says that the mapping already exists, and displaying the existing port map.