Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
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
 
Old March 25th, 2008, 08:50 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old March 26th, 2008, 03:14 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 :)
 
Old March 26th, 2008, 10:13 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
this way give me the wanIP Address.
I need my router Ip.

 
Old March 26th, 2008, 10:17 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Does this help:

http://www.alperguc.com/blog/dotnet/...s-iphostentry/

/- Sam Judson : Wrox Technical Editor -/
 
Old March 26th, 2008, 04:16 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no,
it doesn't help
 
Old March 27th, 2008, 07:53 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old March 27th, 2008, 08:18 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old March 28th, 2008, 09:57 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old March 29th, 2008, 05:42 PM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
find External IP Address in VB.NET remya1000 General .NET 2 March 4th, 2014 12:31 AM
Help me i must Get IP Address pla_2 C# 2005 2 October 12th, 2006 07:51 AM
IP Address sumanghosh Classic ASP Basics 1 April 7th, 2006 11:24 AM
Retreiving IP address & gateway address sjangit VBScript 0 February 3rd, 2004 02:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.