How to retieve public IP of NIC / Router

  • Thread starter Thread starter Pete Kane
  • Start date Start date
P

Pete Kane

Hi All, anyone know of a way to programatically get the WAN ip address of either a NIC or router ?
 
Pete Kane said:
Hi All, anyone know of a way to programatically get the WAN ip address of
either a NIC or router ?

If it is a NIC in your computer, you can get all its network addresses by
means of WMI. There's an example here:
http://www.codeproject.com/cs/system/cstcpipwmi.asp?df=100&forumid=30597&exp=0&select=705111

However, the case of a router is more complex: The router hides the
external address from the internal network, so you can't get directly the
WAN address unless you can login into the router and query its operating
system for the configuration. This is different for different brands and
models, so there isn't a general answer.
If there is a server on the WAN side that you can query, an alternative
is to send a network request to that server, and have the server reply to
you with the return address that it is receiving, which would be the WAN
address of your router. If your WAN connects to the Internet, there are
various servers that offer this service to the public, for instance
http://whatsmyip.org/
 
[...]
However, the case of a router is more complex: The router hides the
external address from the internal network, so you can't get directly
the WAN address unless you can login into the router and query its
operating system for the configuration. This is different for different
brands and models, so there isn't a general answer.

This is true for .NET, since as far as I know there's no Universal Plug
and Play support in .NET. However, if you're willing to use p/invoke to
get at the unmanaged Windows API support for UPnP, that can be used to
find out your "real" Internet address. Not all routers support UPnP, but
most do and so using UPnP would solve the question in most cases.

A truly general-purpose solution doesn't really exist, though as Alberto
suggests you may be able to rely on some server on the Internet that can
reply to a request asking it what your Internet address is.

Most of the time, an application should not need to know what its Internet
address is. For those applications that do need that infomation, most of
the time UPnP will work. In the rare cases when an application needs to
know its Internet address AND UPnP isn't supported, it may well be
sufficient simply to allow the user to enter the IP address by hand.

Pete
 
Peter said:
[...]
However, the case of a router is more complex: The router hides the
external address from the internal network, so you can't get directly
the WAN address unless you can login into the router and query its
operating system for the configuration. This is different for
different brands and models, so there isn't a general answer.

This is true for .NET, since as far as I know there's no Universal Plug
and Play support in .NET. However, if you're willing to use p/invoke to
get at the unmanaged Windows API support for UPnP, that can be used to
find out your "real" Internet address. Not all routers support UPnP,
but most do and so using UPnP would solve the question in most cases.

A truly general-purpose solution doesn't really exist, though as Alberto
suggests you may be able to rely on some server on the Internet that can
reply to a request asking it what your Internet address is.

Most of the time, an application should not need to know what its
Internet address is. For those applications that do need that
infomation, most of the time UPnP will work. In the rare cases when an
application needs to know its Internet address AND UPnP isn't supported,
it may well be sufficient simply to allow the user to enter the IP
address by hand.

Pete

thanks very much to you both
 
i having problem in oracle 9i dataBase------
i want to convert my oracle data to sql 2000.....but i cant convert
the hindi data from oracle to sql 2000...
means......
i having table in oracle9i...
CREATE TABLE SC_CODE (
GRANT_NO VARCHAR2 (3),
H_CODE VARCHAR2 (13),
FIN_YEAR VARCHAR2 (8),
NAME1_HIN NVARCHAR2 (130),
NAME2_HIN NVARCHAR2 (130),
NAME3_HIN NVARCHAR2 (130),
NAME4_HIN NVARCHAR2 (130),
NAME5_HIN NVARCHAR2 (130),
PRIMARY KEY ( GRANT_NO, H_CODE, FIN_YEAR ))


an having data like----------------------->


04 4059600510101 ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿
¿¿¿¿¿¿¿(50¿¿¿¿¿0¿¿0¿0)
1
0
04 4059600510102 ¿¿¿¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿¿
¿¿¿¿¿¿¿ ¿¿
¿¿¿¿¿¿
0
0
04 4059600510300 TEHSILON KE
AVASIYE
66667
0
0
5965
06 2029000010400 ¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿ (¿¿¿0 ¿¿0
07 ¿¿
¿¿¿¿¿¿¿¿¿¿¿¿)
0
2390


these symbol show ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿----->Datain oracle in Hindi.


my task is to covert the whole ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ into hindi as it.
after convertion i saw it never changed it into hindi...it look like
same as in oracle side

i having no problem if i used my front end to insert data into
oracledata base....i having both option hindi and english...
bt when i go throudh my database i never seen the my data in hindi it
look like ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿.

what i did for it......(but never suceed...)

The database character set: use AL32UTF8. You can theoretically use
IN8ISCII, which would give you space savings, but as both Java and
Windows support Hindi (actually: the Devanagari script) through
Unicode, you should use Unicode. This way your database will be
prepared for other languages, including other Indian and South Asian
languages.



1.Have 0racle 9i on windows 2000 enterpiseEdition and client on same

2. regedit and changed NLS_LANG. Change the value to
AMERICAN_AMERICA.UTF8 . For 9idatabse as well as devloper suite.

3. Internet explorer changed the following font Lucida Sans Unicode

4. SELECT * from NLS_DATABASE_PARAMETERS;

...............................................................>
if you have some solution about tha plz mail me the solution.....

wait for reply---------------------->

(e-mail address removed)
(e-mail address removed)
 
alok said:
i having problem in oracle 9i dataBase------
i want to convert my oracle data to sql 2000.....but i cant convert
the hindi data from oracle to sql 2000...
means......
i having table in oracle9i...
CREATE TABLE SC_CODE (
GRANT_NO VARCHAR2 (3),
H_CODE VARCHAR2 (13),
FIN_YEAR VARCHAR2 (8),
NAME1_HIN NVARCHAR2 (130),
NAME2_HIN NVARCHAR2 (130),
NAME3_HIN NVARCHAR2 (130),
NAME4_HIN NVARCHAR2 (130),
NAME5_HIN NVARCHAR2 (130),
PRIMARY KEY ( GRANT_NO, H_CODE, FIN_YEAR ))


an having data like----------------------->


04 4059600510101 ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿
¿¿¿¿¿¿¿(50¿¿¿¿¿0¿¿0¿0)
1
0
04 4059600510102 ¿¿¿¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿¿
¿¿¿¿¿¿¿ ¿¿
¿¿¿¿¿¿
0
0
04 4059600510300 TEHSILON KE
AVASIYE
66667
0
0
5965
06 2029000010400 ¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿ (¿¿¿0 ¿¿0
07 ¿¿
¿¿¿¿¿¿¿¿¿¿¿¿)
0
2390


these symbol show ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿----->Data in oracle in Hindi.


my task is to covert the whole ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ into hindi as it.
after convertion i saw it never changed it into hindi...it look like
same as in oracle side

i having no problem if i used my front end to insert data into
oracledata base....i having both option hindi and english...
bt when i go throudh my database i never seen the my data in hindi it
look like ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿.

what i did for it......(but never suceed...)

The database character set: use AL32UTF8. You can theoretically use
IN8ISCII, which would give you space savings, but as both Java and
Windows support Hindi (actually: the Devanagari script) through
Unicode, you should use Unicode. This way your database will be
prepared for other languages, including other Indian and South Asian
languages.



1.Have 0racle 9i on windows 2000 enterpiseEdition and client on same

2. regedit and changed NLS_LANG. Change the value to
AMERICAN_AMERICA.UTF8 . For 9idatabse as well as devloper suite.

3. Internet explorer changed the following font Lucida Sans Unicode

4. SELECT * from NLS_DATABASE_PARAMETERS;

..............................................................>
if you have some solution about tha plz mail me the solution.....

wait for reply---------------------->

(e-mail address removed)
(e-mail address removed)
you obviously meant to create a new thread not post to an existing one of a totally unrelated matter !!!
 
Pete said:
Hi All, anyone know of a way to programatically get the WAN ip address
of either a NIC or router ?

This should work:

public static string MyIp()
{
WebClient wc = new WebClient();
StreamReader sr = new
StreamReader(wc.OpenRead("http://www.myip.dk/"));
string html = sr.ReadToEnd();
return Regex.Matches(html, @"(?:<title>Your IP:
)(\d+\.\d+\.\d+\.\d+)(?:</title>)")[0].Groups[1].Value;
}

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top