获取传入客户端的IP-TCP-VB.Net
我正在triyng获取传入客户端连接请求的IP:获取传入客户端的IP-TCP-VB.Net,vb.net,sockets,tcp,ip,client,Vb.net,Sockets,Tcp,Ip,Client,我正在triyng获取传入客户端连接请求的IP: 1_ My computer scan all the IP in my network 2_ When it find a valid IP , it send to it a connection request 3_ The destination computer will have to get the IP of the client that is sending a connection request and create a
1_ My computer scan all the IP in my network
2_ When it find a valid IP , it send to it a connection request
3_ The destination computer will have to get the IP of the client that is sending a connection request and create a
New TcpListener(ClientTriyngToConnectIP,64535)
那么有一种方法可以获取试图连接到我的计算机的客户端的IP吗?最后我找到了一个解决方案:这可以在应用程序中实现,以获取另一台试图通过TCP连接到您的计算机的IP 要初始化tcp侦听器,请执行以下操作:
Private InputClient As TcpClient
Public ConnectionRequestListener As TcpListener
Public sub Listener(IncomingPort as String)
Dim IPv4_Address As String = ""
For Each address In Dns.GetHostEntry(Dns.GetHostName()).AddressList
If address.AddressFamily = AddressFamily.InterNetwork Then
IPv4_Address &= address.ToString
Exit For
End If
Next
ConnectionRequestListener = New TcpListener(IPAddress.Parse(IPv4_Address), IncomingPort)
ConnectionRequestListener.Start()
end sub
接受客户:
InputClient = ConnectionRequestListener.AcceptTcpClient()
要获取客户端的IP,请执行以下操作:
IPAddress.Parse((CType(ConnectionRequestListener.RemoteEndpoint,IPEndPoint)).Address.ToString()).ToString
这不是TcpListener的工作方式。您查询的是
TcpListener
正在侦听的本地IP,而不是连接到TcpListener
的客户端的远程IPAcceptTcpClient()
返回一个TcpClient
,客户端的IP在TcpClient.client.RemoteEndPoint中可用