To fetch computer name using C# code, we may consider below methods:
Method 1:
The below Example fetches the computer name from the Environment variables using the static Environment class under the system namespace.
Console.WriteLine(System.Environment.MachineName);
OR
Console.WriteLine(System.Environment.GetEnvironmentVariable("COMPUTERNAME"));
Method 2:
The below Example fetches the computer name from the local DNS using the static DNS class under the System.Net namespace.
Console.WriteLine(System.Net.Dns.GetHostName());
Get Computer name of API requesting client
You can get the computer name of the client using the Request as follows:
Request.ServerVariables["REMOTE_HOST"].ToString()
Get Computer Name of Client using IP address
You can use below code to fetch the computer name of the client using its IP address and static DNS library under the System.Net namespace.
Console.WriteLine(Dns.GetHostEntry(ip).HostName);
The output of the above code results as follows:

Please let us know about your suggestions in the comment box.