2009-01-03 4 views

Répondre

13

Untested, mais je les opérations suivantes:

TcpListener listener = new TcpListener(IPAddress.Any, port); 
TcpClient client = listener.AcceptTcpClient(); 

IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint; 
// .. or LocalEndPoint - depending on which end you want to identify 

IPAddress ipAddress = endPoint.Address; 

// get the hostname 
IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); 
string hostName = hostEntry.HostName; 

// get the port 
int port = endPoint.Port; 

Si vous pouvez faire avec le IPAddress, je sauterais le DNS-recherche inversée, mais vous demandé spécifiquement pour un nom d'hôte.

Questions connexes