Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取传入客户端的IP-TCP-VB.Net_Vb.net_Sockets_Tcp_Ip_Client - Fatal编程技术网

获取传入客户端的IP-TCP-VB.Net

获取传入客户端的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

我正在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 
   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
的客户端的远程IP
AcceptTcpClient()
返回一个
TcpClient
,客户端的IP在
TcpClient.client.RemoteEndPoint中可用