473,669 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15175
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
StaticPortMappi ngCollection object... If anyone knows a workaround for
this, please post!!!

<Code Follows>

Imports NATUPNPLib
Public Class RouterInfo
Dim cRouter As NATUPNPLib.UPnP NAT

Public Sub New()
cRouter = New NATUPNPLib.UPnP NAT
End Sub

Public Function GetExternalIP() As String
Dim lMapper = cRouter.StaticP ortMappingColle ction
Dim lMappedPort As NATUPNPLib.ISta ticPortMapping
Dim lExtIP As String

If Not lMapper Is Nothing Then
For Each lMappedPort In lMapper
lExtIP = lMappedPort.Ext ernalIPAddress( ).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******** ******@TK2MSFTN GP09.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
3173
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
5431
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
10378
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 is on. I was thinking I could make a HTTP Request to a server which displays your IP address as they see it and scrape it out of the response but I was hoping for a method which is less dependent on some server out on the web...
3
2074
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 the internet (with the port opened up in the router, no firewalls), it never connects. I'm thinking it is due to the TcpListener only binding to my local LAN ip. I tried binding it to my internet IP manually and by using...
4
2513
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? -- -iwdu15
1
9458
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 router, and has a static IP address of 192.168.1.10. When I access a page with the following script directly from the server, my WAN IP address is returned (24.x.x.x.), instead of my LAN address. <%
3
8203
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 client to connect to 127.0.0.1 or my LAN IP, the program connects and transfers information successfully. However, when I get somebody else to host the server, or when I try to connect to a server on my own machine using my WAN IP, I currently get a...
4
7749
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 strIPAddress As String strHostName = System.Net.Dns.GetHostName() strIPAddress = System.Net.Dns.Resolve(strHostName).AddressList(0).ToString()
1
3203
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. Until last week, I was using the Airlink router believing my DI was dead (I wasn't able to connect to the net anyway on it) The Airlink router was working perfectly, holding my local IP to a 192.168 address, and I could get the web-admin on...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8587
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.