Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I would like to get IP Address of client with help of asp.net(C#).How can get IP of a client machine in asp.net / C#.
Posted 27-Sep-11 3:59am
Edited 25-Jul-13 7:10am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
Request.ServerVariables("REMOTE_ADDR")
or
Request.UserHostAddress
  Permalink  
Comments
Uday P.Singh at 27-Sep-11 9:11am
   
correct my 5!
shailendra from MP at 27-Sep-11 9:38am
   
Thanks Uday pratap
MaulikDusara at 27-Sep-11 9:18am
   
my 5! to
Sharma Richa at 1-Aug-12 9:18am
   
+5
Member 10538250 at 12-Feb-14 11:20am
   
I want to IP address of client from where my webpages are called in IFRAME
REMOTE_ADDR does not provide that IP address.
Any idea about it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Response.Write("Your IP address is: " + Request.ServerVariables["REMOTE_ADDR"].ToString() + "<br />");
 
Response.Write("You are browsing this site with: " + Request.ServerVariables["http_user_agent"].ToString() + "<br />");
 
Response.Write("The method used to call the page: " + Request.ServerVariables["request_method"].ToString() + "<br />");
 
Response.Write("The server's domain name: " + Request.ServerVariables["server_name"].ToString() + "<br />");
 
Response.Write("The server's port: " + Request.ServerVariables["server_port"].ToString() + "<br />");
 
Response.Write("The server's software: " + Request.ServerVariables["server_software"].ToString() + "<br />");
 
Response.Write("The DNS lookup of the IP address is: " + Request.ServerVariables["REMOTE_HOST"].ToString());
  Permalink  
Comments
MaulikDusara at 27-Sep-11 9:19am
   
shailendra from MP only asked for client IP
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Get users IP address
 
Oct 30, 2006 07:41 AM | LINK
 
HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
 
To get the IP address of the machine and not the proxy use the following code
 
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

public static string GetIpAddress()  // Get IP Address
    {
        string ip = "";     
        IPHostEntry ipEntry = Dns.GetHostEntry(GetCompCode());
        IPAddress[] addr = ipEntry.AddressList;
        ip = addr[2].ToString();
        return ip;
    }
    public static string GetCompCode()  // Get Computer Name
    {   
        string strHostName = "";
        strHostName = Dns.GetHostName();
        return strHostName;
    }
  Permalink  
Comments
CHill60 at 30-Jul-13 11:07am
   
Did you realise this question is nearly 2 years old?
HienHam at 16-Oct-13 0:43am
   
Great Solution. Thanks very much
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

How to get client IP in asp.net(C#).
 
string strHostName = System.Net.Dns.GetHostName();
       string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString();
  Permalink  
v2
Comments
Nelek at 10-Jun-13 4:17am
   
Did you realize that the question is from Sept-2011?
Shaik Rafeeq at 25-Jul-13 4:18am
   
yes Nelek
CHill60 at 10-Jun-13 8:27am
   
And was already solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 244
3 BillWoodruff 210
4 Maciej Los 192
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 30 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100