This is not necessarily possible.
You can attempt to reverse lookup the name from the ip address, using something like
private string[] GetHostnamesForIpAddress(string ipAddress)
{
var hostIp= IPAddress.Parse(ipAddress);
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIp);
return hostInfo.Aliases;
}
On a local network (where your client is local to you, e.g. on a corporate network), this may well be ok, as long as all the clients have reverse ip mappings in DNS.
Over the internet, it is far less likely to work for most clients. You only have the IP address to go on, and generally these won't have reverse DNS mappings set up. In fact, an awful lot of machines out there will be behind proxies and NAT gateways and only have private, non-routable ip addresses, for which you can't possibly do a reverse lookup.