Click here to Skip to main content
11,721,385 members (80,115 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#3.5
public string Get_real_IP(string Provider)
{
	HttpWebRequest SendReq = HttpWebRequest.Create(Provider);
	HttpWebResponse GetRes = SendReq.GetResponse();
 
	System.IO.Stream StreamRes = GetRes.GetResponseStream;
	StreamReader ResStrmRdr = new StreamReader(ResStream, Encoding.UTF8);
 
	string IP = ResStrmRdr.ReadToEnd;
 
	StreamRes.Close();
	GetRes.Close();
 
	return IP;
}
Posted 11-Oct-11 0:18am
dreamz9819
Edited 11-Oct-11 0:22am
P.Salini14.9K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

string IP = GetIP();
 
    public string  GetIP()
    {
        string Str = "";
        Str = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(Str);
        IPAddress[] addr = ipEntry.AddressList;
        return addr[addr.Length - 1].ToString();
 
    }
  Permalink  
Comments
asmaa elbattanony at 25-Jan-12 10:33am
   
Thanx Kishorekke
Your Solution Worked like a charm ^_^
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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:08am
   
As per my earlier comment - did you realise this question is nearly 2 years old.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

string VisitorsIPAddr = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (VisitorsIPAddr != null || VisitorsIPAddr !=String.Empty)
                    {
                        VisitorsIPAddr = Request.ServerVariables["REMOTE_ADDR"];
                    }
you can get visitors ip address from this.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 510
1 OriginalGriff 249
2 Mika Wendelius 170
3 F-ES Sitecore 80
4 cyycoish 70
0 Sergey Alexandrovich Kryukov 2,209
1 OriginalGriff 969
2 F-ES Sitecore 660
3 Maciej Los 609
4 Richard MacCutchan 560


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 7 Oct 2014
Copyright © CodeProject, 1999-2015
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