Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/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
Windows 如何更改gethostbyname返回的IP地址列表顺序?_Windows_Networking_Ipv4_Gethostbyname - Fatal编程技术网

Windows 如何更改gethostbyname返回的IP地址列表顺序?

Windows 如何更改gethostbyname返回的IP地址列表顺序?,windows,networking,ipv4,gethostbyname,Windows,Networking,Ipv4,Gethostbyname,我有一个应用程序,它调用gethostbyname并显示h_addr_列表中的第一个IP地址。在安装了VMware且具有多个虚拟适配器的计算机上,我的应用程序始终返回其中一个虚拟适配器的IP地址。我始终希望我的应用程序为我提供物理适配器的IP地址。 因此,我想重新排列我的虚拟适配器,使物理适配器的IP地址在列表中排在第一位。我试过了所有的建议- 他们都没有工作。我也在做了更改后重新启动了我的系统。有没有其他方法可以更改网络适配器的顺序?假设没有,如何通过代码确保始终获得物理适配器的IP地址

我有一个应用程序,它调用gethostbyname并显示h_addr_列表中的第一个IP地址。在安装了VMware且具有多个虚拟适配器的计算机上,我的应用程序始终返回其中一个虚拟适配器的IP地址。我始终希望我的应用程序为我提供物理适配器的IP地址。

因此,我想重新排列我的虚拟适配器,使物理适配器的IP地址在列表中排在第一位。我试过了所有的建议-

他们都没有工作。我也在做了更改后重新启动了我的系统。有没有其他方法可以更改网络适配器的顺序?假设没有,如何通过代码确保始终获得物理适配器的IP地址

我的操作系统是Windows8。这是我的ipconfig/all输出-

Windows IP Configuration

   Host Name . . . . . . . . . . . . : Win8x64D3b
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : NESSINBLR.COM

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : NESSINBLR.COM
   Description . . . . . . . . . . . : Intel(R) 82566DM-2 Gigabit Network Connec
tion
   Physical Address. . . . . . . . . : 00-0F-FE-E7-00-A6
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::bc7c:6cf5:e8ed:c874%12(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.26.82.152(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.252.0
   Lease Obtained. . . . . . . . . . : Wednesday, June 19, 2013 2:55:44 AM
   Lease Expires . . . . . . . . . . : Friday, June 21, 2013 2:55:38 AM
   Default Gateway . . . . . . . . . : 172.26.80.1
   DHCP Server . . . . . . . . . . . : 172.26.116.52
   DHCPv6 IAID . . . . . . . . . . . : 251662334
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-3D-50-E5-00-0F-FE-E7-00-A6

   DNS Servers . . . . . . . . . . . : 172.26.82.152
   Primary WINS Server . . . . . . . : 172.26.82.152
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter VMware Network Adapter VMnet1:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet
1
   Physical Address. . . . . . . . . : 00-50-56-C0-00-01
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::d59f:e785:bc67:74c4%17(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.3.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 251678806
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-3D-50-E5-00-0F-FE-E7-00-A6

   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet
8
   Physical Address. . . . . . . . . : 00-50-56-C0-00-08
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::3d00:a19f:32b5:5c52%18(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.5.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 268456022
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-3D-50-E5-00-0F-FE-E7-00-A6

   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter isatap.{A80B07CA-01EF-411D-BB81-A4E2F06D588B}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.NESSINBLR.COM:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : NESSINBLR.COM
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{8D6220B3-8F39-4514-8C4E-C79D8263C2B8}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
我的应用程序总是返回192.168.5.1,而不是172.26.82.152


请帮忙。

我见过类似的东西。这并不能完全回答你的问题,但这就是我的答案

remoteHost = gethostbyname(ac);
int i = 0;
if (remoteHost->h_addrtype == AF_INET)
{
    //while (remoteHost->h_addr_list[i] != 0) 
    //{
    //  addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
    //}
    addr.s_addr = *(u_long *) remoteHost->h_addr_list[0];
}
我已经注释掉了while循环。这一部分只是在适配器列表中不断循环,最终在最后一个适配器上停止(在我们的例子中,是VMware适配器)

使用h_addr_列表[0]可以提供我的物理适配器。然而,我不确定顺序是如何确定的,也不确定我如何区分哪些是物理的,哪些是虚拟的


希望这能有所帮助。

我也看到过类似的情况。这并不能完全回答你的问题,但这就是我的答案

remoteHost = gethostbyname(ac);
int i = 0;
if (remoteHost->h_addrtype == AF_INET)
{
    //while (remoteHost->h_addr_list[i] != 0) 
    //{
    //  addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
    //}
    addr.s_addr = *(u_long *) remoteHost->h_addr_list[0];
}
我已经注释掉了while循环。这一部分只是在适配器列表中不断循环,最终在最后一个适配器上停止(在我们的例子中,是VMware适配器)

使用h_addr_列表[0]可以提供我的物理适配器。然而,我不确定顺序是如何确定的,也不确定我如何区分哪些是物理的,哪些是虚拟的

希望对你有点帮助