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.

14 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. 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
  5. 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
  6. There are a few methods for finding your Ethernet and interchanges convention data.myip info

    ReplyDelete
  7. Wow, what an information. Very interesting. Thanks for sharing.

    Best Mobility Services | Austere Technologies

    ReplyDelete
  8. Some site proprietors make utilization of the IP area database to modify their quality on the web.is wearable technology safe

    ReplyDelete
  9. The separation between your nation and the server's nation matters a ton. The more drawn out the separation, the moderate the association speed will be. router ip

    ReplyDelete
  10. Rousing and particularly significant, significantly recommended for all bloggers out there.
    192 .168.0.1

    ReplyDelete
  11. Such an excellent and interesting blog, do post like this more with more information, this was very useful. Salesforce Training India  

    ReplyDelete

Followers