Wrox Programmer Forums
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 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 31st, 2009, 08:24 AM
Authorized User
 
Join Date: Apr 2007
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get Visitor's IP Address

Hello Friend,
I want to get the Visitor's IP Address. For it, i'm using the following code
<b>
string hostName = Dns.GetHostName();
IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
IPAddress[] ipAddress = hostEntry.AddressList;
string name = null;
for(int i=0;i&lt;ipAddress.Length;i++)
{
name = name + ipAddress[i].ToString()+"&lt;br&gt;";
}
Response.Write(name.ToString());
</b>
This code is showing the correct IPAddress of the local computer on localhost but as i upload this code over my server it gives me the following IPAddress not of my computer
<b>
66.63.181.68
66.63.181.93
216.45.55.186
</b>
Secondly, i use the following code
<b>
string hostName1 = Request.UserHostName.ToString();
Response.Write(hostName1.ToString());</b>
But this is giving the IPAddress of the Main computer, I mean there are four computers, sharing the internet connection from my PC and when i visit the page from any of those computers it always give me the IP of my PC
 
Old March 31st, 2009, 08:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Maybe I will not be very clear with why are you seeing this, but you could read about how IP works.

If your computer is giving internet to the rest, then for example, the only computer that has an IP address is the one that is really connecting to the internet. But maybe you are seeing a different address, because if you are in a intranet is not the same address like when you connect to outside. My pc has an IP inside my office, but when I go outside it has another IP. The problem is not your code, the problem is your logic. ;)
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old March 31st, 2009, 09:08 AM
Authorized User
 
Join Date: Apr 2007
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok sir, i got it but i've get the information of that particular system or computer. Is it any way please suggest me





Similar Threads
Thread Thread Starter Forum Replies Last Post
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
How to get IP address shankhan Classic ASP Databases 6 March 10th, 2005 04:18 PM
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.