locked
Get a client's hostname on a lan network. RRS feed

  • Question

  • User1670624291 posted

    Hi,

    I ask if it is possible in MVC to ask for the hostname of the client's browser?

    I intend to save the hostaname in a field to know which machine made the last change, this in a lan network in which all the machines are identified.

    I Tried @System.Net.Dns.GetHostName() and it makes perfect sense to give only the hostaname of the server.

    Thanks,

    Tuesday, May 25, 2021 3:01 PM

Answers

All replies

  • User-821857111 posted

    I ask if it is possible in MVC to ask for the hostname of the client's browser?
    Nope. Use some kind of membership instead. Get the users to log in so that they aren't anonymous.

    Tuesday, May 25, 2021 6:22 PM
  • User287926715 posted

    Hi MiguelMi,

    No, you can't. HTTP header data is everything except standard network information (such as IP address) (it is also not guaranteed to be the client's IP address-it may be the client's network address). The closest thing you can find is whether the hostname exists, and even then, just like an IP address, there is no guarantee that it is a computer name. The possible exception is the internal network (LAN).

    Best Regards,

    ChaoDeng

    Wednesday, May 26, 2021 2:39 AM
  • User1670624291 posted

    The closest thing you can find is whether the hostname exists, and even then, just like an IP address, there is no guarantee that it is a computer name. The possible exception is the internal network (LAN).

    I was able to give an example of how it would work, because what I intend to consult is in LAN network

    Thanks,

    Wednesday, May 26, 2021 8:37 AM
  • User475983607 posted

    You misunderstand.  HTTP and TCP does not have a specification for the originating client IP address.  There's no need for this information on the Web.

    If you are messing around a proprietary project on a local network then you must understand that you are the only person who knows how the network is configured.  Forum members can't answer your question since we have no idea how your LAN is configured. 

    Needing this type of network information indicates a browser based application might be the wrong application design.  Your application is dependent totally dependent on the network configuration.  Maybe you need to write a client application because the client knows its machine name and IP.

    Wednesday, May 26, 2021 2:57 PM
  • User-474980206 posted

    Assuming it’s a local lan with no firewalls and any proxies forward the ipaddresss you get the client ipaddress

    var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;

    Then using a dns library (assuming the dhcp server updates the dns server) you do a reverse lookup. As this may slow down the requests it usually done by a queue or background task.

    Wednesday, May 26, 2021 3:07 PM
  • User753101303 posted

    You could also use X-Forwarded-For - HTTP | MDN (mozilla.org) first and Dns.GetHostEntry Method (System.Net) | Microsoft Docs

    You don't have ay authentication in place. usually you care rather about which user have done the change rather than from which machine.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 3:14 PM