Monday, September 21, 2009

how to get ip address using asp.net

How to get Internet protocol address using asp.net.Internet protocol is a communication between the nodes. Internet protocol, which is used to track a system host and used address the location. If we need to identify the user
who are all accessing our website and store the Internet protocol address in our database is very simple and very easier.

This is the way to track the users Internet protocol address.Fetch a client's Internet protocol address as soon as he access our web site in asp.net.
Some of them may use a proxy Internet protocol address. But we can get their Internet protocol address with this simple code.

Here am giving two methods to find the Internet protocol adress.


using System.Net;//Add the Namespace
//Get Visitor IP address method
public string GetVisitorIpAddress()
{
string stringIpAddress;
stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (stringIpAddress == null) //may be the HTTP_X_FORWARDED_FOR is null
{
stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];//we can use REMOTE_ADDR
}
return "Visitor IP is "+stringIpAddress;
}

//Get Lan Connected IP address method
public string GetLanIPAddress()
{
//Get the Host Name
string stringHostName = Dns.GetHostName();
//Get The Ip Host Entry
IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName);
//Get The Ip Address From The Ip Host Entry Address List
IPAddress[] arrIpAddress = ipHostEntries.AddressList;
return arrIpAddress[arrIpAddress.Length - 1].ToString();
}

//Get The Visitor Ip Address
string strVisitorIpAddress = GetVisitorIpAddress();

//Get The Lan Ip Address
string strLanIpAddress = GetLanIPAddress();

you will get their ip address.

12 comments:

  1. Great article thanks for sharing

    We can also submit our .net related links on http://www.dotnettechy.com to increase traffics of your website / blog

    Its kind of social networking for .Net professionals only

    ReplyDelete
  2. ASP.Net application is running on server in IIS , but i cant get the ip address of the local systems through your code, it returns the ip address of server .

    ReplyDelete
  3. Excellent items from you, mаn. I have consiԁer your stuff previous tօ and yoս
    are simply too magnificent. ӏ actually liƙe wҺat you've
    acquired гight here, really like what үou are stating
    and tɦe best way whеrein you say it. You are maҟing it entertaining аnd ʏоu still care for
    to stay it smart. Ӏ can't wait tߋ read far more feom yօu.
    Thіs iss гeally a greаt website.

    Feel free to surf tߋ my website :: coupons

    ReplyDelete
  4. I have read your blog its very attractive and impressive. I like it your blog.

    Dot Net Training in Chennai Dot Net Training in Chennai .Net Online Training .Net Online Training Dot Net Training in Chennai Dot Net Training in Chennai


    Dot Net Online Training Dot Net Online Training LINQ Online Training LINQ Online Training ASP.NET Online Training ASP.NET Online Training

    ReplyDelete
  5. his article is very nice and easy to understand, it was a very weighty once thanks a lot admin can hopefully be improved in the future and pardon me permission to share the article here : Cara menyembuhkan gagal jantung

    ReplyDelete
  6. articles that you provide a very interesting and very useful for me, thank you very much admin and pardon me permission to share articles herein may be useful also for the reading : cara menyembuhkan penyakit katup jantung

    ReplyDelete
  7. I still liked this article, good, good content, and unique design.Thank you for sharing the article.
    cara alami menyembuhkan ruam popok

    ReplyDelete
  8. Anyone tracking the IP address of the computer will then see this fake IP and not the original one that was provided by the Internet Service Provider. hiding ip address

    ReplyDelete
  9. There are a few methods for finding your Ethernet and interchanges convention data.myip info

    ReplyDelete

Followers