How to get the computer name (host name in the web application)?

how can I get the name of the client computer in a web application. The user is online.

Hi

// Already tried this option

string IP = System.Web.HttpContext.Current.Request.UserHostAddress;
string compName = DetermineCompName(IP);

System.Net.IPHostEntry teste = System.Net.Dns.GetHostEntry(IP);
ssresult = IP + "   -   " + teste.HostName;

// TODO: Write implementation for action

private static string DetermineCompName(string IP)
{
   IPAddress myIP = IPAddress.Parse(IP);
   IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
   string[] compName = GetIPHost.HostName.ToString().Split('.');
   return compName[0];
}

All this gives me only IP: /

+3
source share
4 answers

You cannot do this in such a way that it guarantees a job.

The closest thing you can get is to follow the path of the reverse dns search with the help System.Net.Dns.GetHostEntrythat you have already tried.

The problem is that your computer is not able to find the host name of the remote web client only through its IP address (if it is not on the same subnet, in which case you can restore it).

DNS, IP- [ , nslookup , ], IP-.

, , , . "1.2.3.4", "machine-1.2.3.4" .

, , IP- . , , , " ".

,

nslookup <some ip>

( ), ?

, System.Net.Dns.GetHostEntry , , , , , .

+3

Windows - System.Environment.MachineName

0

, , , .

nslookup . , :

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
System.Diagnostics.ProcessStartInfo sInfo = new System.Diagnostics.ProcessStartInfo("nslookup.exe", "192.168.1.100");
string result = process.StandardOutput.ReadToEnd(); 

.

0

, Windows, , :

<script type="text/javascript"> 
        function create() 
        { 
           var net = new ActiveXObject("wscript.network"); 
           document.write(net.ComputerName); 
        } 
</script> 
0

Source: https://habr.com/ru/post/1745820/