getting host name

Discussion in 'ASP .Net' started by Brian Henry, Mar 16, 2005.

  1. Brian Henry

    Brian Henry Guest

    is there a way to get the host name of someone? like mine is
    68-23-123-123-pitt-pa.adelphia.net?

    Request.UserHostName doesn't seem to return the host name like it states in
    the documentation, only gives me back an IP address.. which is what I
    assumed Request.UserHostAddress would do... they both return the same values
    all the time
     
    Brian Henry, Mar 16, 2005
    #1
    1. Advertisements

  2. Use :
    Request.ServerVariables("HTTP_HOST")
     
    Juan T. Llibre, Mar 16, 2005
    #2
    1. Advertisements

  3. Brian Henry

    Brian Henry Guest

    thanks a lot

     
    Brian Henry, Mar 16, 2005
    #3
  4. Brian Henry

    Brian Henry Guest

    I just tried that and it seems to only be returning the host name of the
    server, shouldn't this be the host name of the client? which is what I want
    not the server the application it is running on... REMOTE_HOST returns the
    client IP, but I want the client host name.. thanks!
     
    Brian Henry, Mar 16, 2005
    #4
  5. Brian Henry

    recoil Guest

    the REMOTE_HOST returning the IP instead of the actual hostname is a
    server configuration. Most servers disable reverse lookup because it
    does slow things down unnecessarily.

    You will usually have to do the reverse lookup yourself manually and
    you can use the following code as a basis

    System.Net.IPHostEntry TmpEntry =
    System.Net.Dns.GetHostByAddress(Request.ServerVariables["REMOTE_ADDR"]);
    Response.Write(TmpEntry.HostName + "<br />");
     
    recoil, Mar 16, 2005
    #5
  6. re:
    No. It's the host name of the http server.

    re:
    You can't have that, since the client is not hosting anything.

    You could, if you need that info, do a reverse DNS query.
    *That* would give you the client's name, if any exists.
     
    Juan T. Llibre, Mar 16, 2005
    #6
  7. Hmm...

    I thought that would get you the machine's name,
    but not the DNS name.
     
    Juan T. Llibre, Mar 16, 2005
    #7
  8. Brian Henry

    Kvako

    Joined:
    Mar 9, 2012
    Messages:
    1
    Likes Received:
    0
    Use this instead:

    System.Net.IPHostEntry ip
    = System.Net.Dns.GetHostByAddress(Request.UserHostAddress);

    string hostname = ip.HostName;
     
    Kvako, Mar 9, 2012
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.