You must Sign In to post a response.
  • Category: ASP.NET

    Finding Ip Address and storing

    I have a Intranet application and i need to store ip Address of the computer using it after logging.

    I try the below code but not working.

    Dim strIpAddress As String = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If strIpAddress Is Nothing Then
    Label2.Text = Request.ServerVariables("REMOTE_ADDR")
    End If

    Can anybody help in regarding it.

  • #762865
    Hai Syed Thahir Hussain,
    To get the ip address, first you need to get the host name and then based on the hostname, you can retrieve IP host entry and then based on the ip host entry, you can get the ip address as below:

    strHostName = DNS.GetHostName ();
    var entry = DNS.GetHostByName (strHostName);
    var ipAddressCollection = entry.AddressList;
    foreach(var item in ipAddressCollection)
    // get the ipaddress here

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #762872

    Hello Syed Thahir Hussain,

    This code worked for me:

    Dim ipaddress As String

    ipaddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If ipaddress = "" OrElse ipaddress Is Nothing Then
    ipaddress = Request.ServerVariables("REMOTE_ADDR")
    End If

    I have used it in Contact form.

    See the attached image. It's an output.

    Hope this will help you to understand.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #762876
    The code helps lot.


  • Sign In to post your comments