终端有多网卡,怎么判断哪块是连通外网网络的

davidcao007 2017-12-02 05:09:15
电脑可能有多块网卡的,有的只连内网,有的可能是连外网 比如能访问百度.

怎么能分辨出哪块网卡是连外网的,
找出以后就禁用,禁用的晓得处理,现在就是怎么分区哪块网卡是通外网
谢谢
...全文
845 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
l357630798 2017-12-05
  • 打赏
  • 举报
回复
引用 9 楼 zgl7903 的回复:
bind 后 可以 ping baidu sina 等 参考我的博客代码 使用 ICMP 和 RAW Sockets实现 ping 类
LZ可以考虑把这个代码移植到你的项目里,然后ping就可以了,不用考虑WIN7/XP之类的了。 ICMP协议实现ping。点赞!
davidcao007 2017-12-05
  • 打赏
  • 举报
回复
引用 9 楼 zgl7903 的回复:
bind 后 可以 ping baidu sina 等 参考我的博客代码 使用 ICMP 和 RAW Sockets实现 ping 类
非常谢谢,目前在测试使用提供的方法,
davidcao007 2017-12-04
  • 打赏
  • 举报
回复
引用 3 楼 zgl7903 的回复:
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


谢谢回复,但是公网上没有自己服务器的,比如能上网页就算通外网的, 这么bind 以后 connect 也不好连 baidu 新浪这些服务把 还有一个地方不明白,
引用 3 楼 zgl7903 的回复:
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


谢谢 回复,但是公网上没有自己服务器的,比如能上网页就算通外网的, 这么bind以后 包即使出去 但是没法判断结果
davidcao007 2017-12-04
  • 打赏
  • 举报
回复
楼上 回复乱了,多点了引用
davidcao007 2017-12-04
  • 打赏
  • 举报
回复
引用 3 楼 zgl7903 的回复:
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


引用 3 楼 zgl7903 的回复:
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


引用 3 楼 zgl7903 的回复:
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


谢谢回复,但是公网上没有自己服务器的,比如能上网页就算通外网的, 这么bind 以后 connect 也不好连 baidu 新浪这些服务把
引用 3 楼 zgl7903 的回复:
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


谢谢回复,公网上没有自己搭建的服务器, 常见的如果能ping通百度就算通外网, 所以这个connect 服务器 连哪个地方嘛,
引用 4 楼 boylafong 的回复:
一个一个禁用,然后一直ping百度,ping不通了就是外网的
这么误伤风险太大,会把正常的内网通信的网络给关了
boylafong 2017-12-04
  • 打赏
  • 举报
回复
一个一个禁用,然后一直ping百度,ping不通了就是外网的
zgl7903 2017-12-04
  • 打赏
  • 举报
回复
gethostbyname 列举出所有地址, 逐个bind, 然后connect测试连接服务器

   void EnumIP()
   {
      char     szHostname[100];
      HOSTENT *pHostEnt;
      int      nAdapter = 0;

      gethostname( szHostname, sizeof( szHostname ));
      pHostEnt = gethostbyname( szHostname );

      while ( pHostEnt->h_addr_list[nAdapter] )
      {
         // pHostEnt->h_addr_list[nAdapter] is the current address in host
         //  order.

         nAdapter++;
      }
   }


davidcao007 2017-12-04
  • 打赏
  • 举报
回复
引用 1 楼 l357630798 的回复:
ping -S xxx.xxx.xxx.xxx www.baidu.com 通,外网。反之,内网。
谢谢,查了下 -S 参数,win7下支持, xp下 ping没有这个命令参数,虽说xp慢慢被替换了,但还是存在一批xp的机器头疼
zgl7903 2017-12-04
  • 打赏
  • 举报
回复
bind 后 可以 ping baidu sina 等 参考我的博客代码 使用 ICMP 和 RAW Sockets实现 ping 类
xiaohuh421 2017-12-04
  • 打赏
  • 举报
回复
要做到这么极至的兼容性, 那么系统靠系统本身的状态肯定是不行了. 只能一块网卡一块网卡的去试了. 外网没有服务器, 那么就只能使用公开的, 比较稳定的网站来做. 比如 一些DNS服务器, baidu之类的. 这些服务器只要开了http的, 至少支持TCP 80端口连接的.
l357630798 2017-12-02
  • 打赏
  • 举报
回复
ping -S xxx.xxx.xxx.xxx www.baidu.com 通,外网。反之,内网。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧