2009-01-03 9 views

risposta

13

testato, ma vorrei provare il seguente:

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; 

Se si può fare che fare con l'IPAddress, vorrei saltare il DNS-ricerca inversa, ma è chiesto specificamente per un hostname.

Problemi correlati