 |
| C# 2005 For discussion of Visual C# 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 25th, 2008, 08:50 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
get external IP Address
Hi
i write a FTP Application.
in my computer there is two Ip address(except my wanIp).
one start with 192.168...(this is the My LAN IP) and other start with 10.120..(this the My ADSL Router IP)
i use DNS Class for getting the Ip Adrress list and it works fun.
but the DNS Class Get me all local IP address. My App works with external Ip (in this case,the Ip that start with 10.120...)
I want just Get the external Ip of my computer.
thanx
|
|

March 26th, 2008, 03:14 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Create WebClient object and call it's OpenRead method, give "www.whatismyip.org" as parameter. Attach StreamReader to the Stream you get as result of OpenRead. Call StreamReader.ReadToEnd and there you have it as nice little dotted IP string :)
|
|

March 26th, 2008, 10:13 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
this way give me the wanIP Address.
I need my router Ip.
|
|

March 26th, 2008, 04:16 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
no,
it doesn't help
|
|

March 27th, 2008, 07:53 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Could you describe your network setup a bit since I don't quite understand this.. Do you have something like
Internet - WAN/router - computer(s)
or
Internet - WAN/router - router - computer(s)
And which IP address you are trying to get? The one that computer(s) see? That can be read from routing table: http://www.pinvoke.net/default.aspx/...ptersInfo.html
|
|

March 27th, 2008, 08:18 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Strange, the code works fine for me - it returns an array of IP addresses if you have more than one, so one of those should be the correct IP Address. Can you tell me what it is returning.
/- Sam Judson : Wrox Technical Editor -/
|
|

March 28th, 2008, 09:57 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
thanks for your replies.
Let's me to explain this problem in another way.
see,
in my computer,i have an adsl router that connect to my onboard lan card with a cross cabl(cat5)
now, when i connected to internet, there is 3 IP Address for me.
first, the WANIP Address, secnd my router IP address and last My onboar LanCard IP Address.
Now, i wanty to get the Router IP Address directly.
i dont want get All of the IP Addresses in my computer then splitt them.
just i want to get the router IP Address.
hope you understand.
bests
|
|

March 29th, 2008, 05:42 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well then you have to dig it out from the interface table. Call GetAdaptersInfo to get the table, search for the LAN interface and read it's default gateway. That should be the correct one.
Take notice that there can be multiple interfaces with different subnets and different gateways. Some of them can even be virtual interfaces. I once had to deal with this stuff when I was writing network drivers for Windows and boy it was fun :)
|
|
 |