473,382 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Get external IP address of Router

Hi,

I'm running a small network and need to get the external IP address of my
router so that I can update my DNS forwarding service should my IP change
(it's a dynamic one)... I can get the IP addresses of all the machines in
the network, and can get the internal IP address of the default gateway (the
router), but I need to get the external IP address...

Any pointers?

Thanks

Lorne
Nov 20 '05 #1
1 15116
OK, I've solved my own problem... For anyone interested, here's what you
need to do...

First, add a reference to the NATUPnP 1.0 Type Library. Then paste the
following code into a class. When done, instantiate the class as you
normally would and call the GetExternalIP function. This works find and you
can expand on this functionality to iterate through each of the configured
ports on your router. The only limitation I've found with that though it
that Microsofts implementation of the uPnP library cannot handle port ranges
so any setup on your router like this will NOT be returned in the
StaticPortMappingCollection object... If anyone knows a workaround for
this, please post!!!

<Code Follows>

Imports NATUPNPLib
Public Class RouterInfo
Dim cRouter As NATUPNPLib.UPnPNAT

Public Sub New()
cRouter = New NATUPNPLib.UPnPNAT
End Sub

Public Function GetExternalIP() As String
Dim lMapper = cRouter.StaticPortMappingCollection
Dim lMappedPort As NATUPNPLib.IStaticPortMapping
Dim lExtIP As String

If Not lMapper Is Nothing Then
For Each lMappedPort In lMapper
lExtIP = lMappedPort.ExternalIPAddress().ToString
Exit For
Next
GetExternalIP = lExtIP
Else
GetExternalIP = "<Unable to resolve external IP>"
End If
End Function

End Class
"Lorne Smith" <no@spam.com> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
Hi,

I'm running a small network and need to get the external IP address of my
router so that I can update my DNS forwarding service should my IP change
(it's a dynamic one)... I can get the IP addresses of all the machines in
the network, and can get the internal IP address of the default gateway (the router), but I need to get the external IP address...

Any pointers?

Thanks

Lorne

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris Fink | last post by:
Help....I am trying to use the System.net namespace to determine the Internet (WAN) IP Address of my computer. No luck finding any such class so far. Any ideas?
2
by: Tim | last post by:
Hi, I was wondering if anyone knows how to get the external IP address (the address beyond the router ) using C# code? Basically this is the address that appears on the internet. Thanks Tim
8
by: MrNobody | last post by:
I need to find out the IP address of my local network on the WAN. There is alot of information on getting my local machine IP address but I can't find anything for getting the IP address my network...
3
by: mscdex | last post by:
I have a test application that transfers files from a client to a server. I've been locally testing this on my local LAN and it has been working fine. However, when I try to transfer a file over...
4
by: iwdu15 | last post by:
Hi, im using this code to get a computers IPAddress Net.Dns.GetHostEntry(Net.Dns.GetHostName()).AddressList(0) but that only gets the Lan IPAddress....how can i get the internet IP address? --...
1
by: danknauf | last post by:
I have a webserver which is behaving strangely. The server is a fresh copy of Windows 2003 running IIS with default options + Active Server Pages installed. The server is connected to a Linksys...
3
by: RFD | last post by:
I've been slaving at this problem for over a week, and would appreciate some help from you kind folks. Basic Problem: I have made a server program and a client program. When I try to use the...
4
by: kimiraikkonen | last post by:
Hi, I'm connected through router and i have a local ip address as well starting with 192.168.x.x. However i can read local ip address fine with that code: Dim strHostName As String Dim...
1
by: izecul | last post by:
Hi, I'm a newbie here, and what I know about networking you can probably copy on a matchbook :) That said, here's my problem: I've got two wireless routers - D-Link DI-524 and Airlink AR325W....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.