Tuesday, December 11, 2012

ASP.NET Tip : Capturing Public IP Address of Client

Scenario: - You want to capture the IP address of the person who is logging in to your application and entering data.


Solution:-
To solve this scenario , you can parse the server variables in the request. The function for retrieving the IP Address is as follows. PLEASE NOTE THAT YOU WILL GET ONLY THE PUBLIC IP ADDRESS AND NOT THE CLIENT MACHINE IP IN A NETWORK. 



Public Function GetIpAddress() As String
Dim stringIpAddress As String
stringIpAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If stringIpAddress Is Nothing Then
stringIpAddress = Request.ServerVariables("REMOTE_ADDR")
End If
Return "Visitor IP Address is " & stringIpAddress
End Function



Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments : on " ASP.NET Tip : Capturing Public IP Address of Client "