C# 如何通過TcpClient取得remote ip 和port (客戶/用戶IP和PORT)
C# 如何通過TcpClient取得remote ip 和port (客戶/用戶IP和PORT)
資料來源: https://blog.51cto.com/yerik/493795
code
//--- //得到用戶IP和PORT ~https://blog.51cto.com/yerik/493795 Socket GetSocket(TcpClient cln) { Socket s = cln.Client; return s; } string GetRemoteIP(TcpClient cln) { string ip = GetSocket(cln).RemoteEndPoint.ToString().Split(':')[0]; return ip; } public int GetRemotePort(TcpClient cln) { string temp = GetSocket(cln).RemoteEndPoint.ToString().Split(':')[1]; int port = Convert.ToInt32(temp); return port; } //---得到用戶IP和PORT