TCP-Socket到虚拟机的IP地址

IP adress for TCP-Socket to virtual machine

本文关键字:IP 地址 虚拟机 TCP-Socket      更新时间:2023-10-16

我想在我的windows-pc和linux虚拟机之间建立套接字通信。windows机器是服务器。我写了一个c++程序,在winpc上设置服务器和一个python程序,在VM上设置客户端,但是我如何连接它们?我使用SOCK_STREAMAF_INET,所以我需要一个端口和ip地址连接到服务器。我只是想知道我应该使用什么ip地址,因为它不与IPv4一起工作,这是因为它是错误的ip地址还是因为我的程序中的错误?

编辑1:抱歉数据不足:

我使用Oracle Virtual Box,它的网络配置被设置为default, NAT。当我在host (windows) cmd中运行ipconfig时。我得到了多个ip地址:

Windows IP Configuration

Wireless LAN adapter Wireless Network Connection:
   Media State . . . . . . . . . . . : *
   Connection-specific DNS Suffix  . : *
Ethernet adapter Local Area Connection:
   Connection-specific DNS Suffix  . : ********
   Link-local IPv6 Address . . . . . : *
   IPv4 Address. . . . . . . . . . . : *
   Subnet Mask . . . . . . . . . . . : *
   Default Gateway . . . . . . . . . : *
**Ethernet adapter VirtualBox Host-Only Network:
   Connection-specific DNS Suffix  . :*
   Link-local IPv6 Address . . . . . : *
   Autoconfiguration IPv4 Address. . : *
   Subnet Mask . . . . . . . . . . . : '*
   Default Gateway . . . . . . . . . :***
Tunnel adapter isatap.{*}:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
Tunnel adapter 6TO4 Adapter:
   Connection-specific DNS Suffix  . : ********
   IPv6 Address. . . . . . . . . . . : *
   Default Gateway . . . . . . . . . :
Tunnel adapter isatap.{5289AB9F-2C9F-4CBE-B826-149B3CFBB45F}:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :*
Tunnel adapter isatap.******:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : *******
Tunnel adapter Teredo Tunneling Pseudo-Interface:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :*

我倾向于认为"以太网适配器VirtualBox主机专用网络"下的ipv6地址是正确的。我试着对lan地址和VirtualBox的纯主机网络地址都进行了ping,都有结果。我也试过tracerout在终端,但没有工作。有什么想法?

我使用"以太网适配器本地连接,链路到链路IPv6"。在阅读了NAT之后,我想这是有道理的!