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. Advertising

  2. Use :
    Request.ServerVariables("HTTP_HOST")



    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Brian Henry" <> wrote in message
    news:%...
    > 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
    Juan T. Llibre, Mar 16, 2005
    #2
    1. Advertising

  3. Brian Henry

    Brian Henry Guest

    thanks a lot

    "Juan T. Llibre" <> wrote in message
    news:...
    > Use :
    > Request.ServerVariables("HTTP_HOST")
    >
    >
    >
    > Juan T. Llibre
    > ASP.NET MVP
    > http://asp.net.do/foros/
    > Foros de ASP.NET en Español
    > Ven, y hablemos de ASP.NET...
    > ======================
    >
    > "Brian Henry" <> wrote in message
    > news:%...
    >> 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
    #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!


    "Juan T. Llibre" <> wrote in message
    news:...
    > Use :
    > Request.ServerVariables("HTTP_HOST")
    >
    >
    >
    > Juan T. Llibre
    > ASP.NET MVP
    > http://asp.net.do/foros/
    > Foros de ASP.NET en Español
    > Ven, y hablemos de ASP.NET...
    > ======================
    >
    > "Brian Henry" <> wrote in message
    > news:%...
    >> 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
    #4
  5. Brian Henry

    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 />");
    , Mar 16, 2005
    #5
  6. re:
    > shouldn't this be the host name of the client?


    No. It's the host name of the http server.

    re:
    >I want the client host name


    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
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Brian Henry" <> wrote in message
    news:%...
    >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!
    >
    >
    > "Juan T. Llibre" <> wrote in message
    > news:...
    >> Use :
    >> Request.ServerVariables("HTTP_HOST")
    >>
    >>
    >>
    >> Juan T. Llibre
    >> ASP.NET MVP
    >> http://asp.net.do/foros/
    >> Foros de ASP.NET en Español
    >> Ven, y hablemos de ASP.NET...
    >> ======================
    >>
    >> "Brian Henry" <> wrote in message
    >> news:%...
    >>> 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

    >>
    >>

    >
    >
    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
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "" <> wrote in message
    news:...
    > 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 />");
    Juan T. Llibre, Mar 16, 2005
    #7
  8. Brian Henry

    Kvako

    Joined:
    Mar 9, 2012
    Messages:
    1
    Use this instead:

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

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

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vijesh
    Replies:
    0
    Views:
    426
    Vijesh
    Nov 27, 2004
  2. Joey
    Replies:
    0
    Views:
    335
  3. Orpheus66
    Replies:
    0
    Views:
    4,396
    Orpheus66
    Jul 30, 2003
  4. Anil G
    Replies:
    4
    Views:
    22,775
    v_parthi
    Jan 31, 2008
  5. Jerry Qu
    Replies:
    1
    Views:
    445
    lee atkinson
    Feb 20, 2009
Loading...

Share This Page