<i id='742x1'><tr id='742x1'><dt id='742x1'><q id='742x1'><span id='742x1'><b id='742x1'><form id='742x1'><ins id='742x1'></ins><ul id='742x1'></ul><sub id='742x1'></sub></form><legend id='742x1'></legend><bdo id='742x1'><pre id='742x1'><center id='742x1'></center></pre></bdo></b><th id='742x1'></th></span></q></dt></tr></i><div id='742x1'><tfoot id='742x1'></tfoot><dl id='742x1'><fieldset id='742x1'></fieldset></dl></div>

      <tfoot id='742x1'></tfoot>
          <bdo id='742x1'></bdo><ul id='742x1'></ul>

      1. <legend id='742x1'><style id='742x1'><dir id='742x1'><q id='742x1'></q></dir></style></legend>

        <small id='742x1'></small><noframes id='742x1'>

        如何从Objective C中的域名获取IP地址的域名和IP地址?

        How to get Domain Name of IP address and IP address from Domain Name in Objective C?(如何从Objective C中的域名获取IP地址的域名和IP地址?)
            <tfoot id='TQlx2'></tfoot>
          1. <i id='TQlx2'><tr id='TQlx2'><dt id='TQlx2'><q id='TQlx2'><span id='TQlx2'><b id='TQlx2'><form id='TQlx2'><ins id='TQlx2'></ins><ul id='TQlx2'></ul><sub id='TQlx2'></sub></form><legend id='TQlx2'></legend><bdo id='TQlx2'><pre id='TQlx2'><center id='TQlx2'></center></pre></bdo></b><th id='TQlx2'></th></span></q></dt></tr></i><div id='TQlx2'><tfoot id='TQlx2'></tfoot><dl id='TQlx2'><fieldset id='TQlx2'></fieldset></dl></div>

          2. <legend id='TQlx2'><style id='TQlx2'><dir id='TQlx2'><q id='TQlx2'></q></dir></style></legend>
              <tbody id='TQlx2'></tbody>

              <small id='TQlx2'></small><noframes id='TQlx2'>

                  <bdo id='TQlx2'></bdo><ul id='TQlx2'></ul>
                  本文介绍了如何从Objective C中的域名获取IP地址的域名和IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我能够通过使用此问题的答案获取我正在使用的设备/机器的当前 IP 地址.

                  I am able to get the current IP address of my device/machine that I am using - by using this question's answer.

                  我已经解决了这个问题.Java 允许从域名中获取 IP 地址.在Objective C中可能吗?怎么样?

                  I have gone through this question. Java allows to get the IP address from a domain name. Is it possible in Objective C? How?

                  第二个问题是如何通过 IP 地址获取设备/机器的名称.例如,我有一个 IP 地址 192.168.0.74 = 设备名称是什么?在目标 C 中?

                  The second question is How to get the name of device/machine by using its IP address. Say for example I have an IP address 192.168.0.74 = What is the device name? in Objective C?

                  推荐答案

                  我不确定这是否是最好的方法,但它主要适用于我.我输入了 StackOverflow 的 IP 地址 (69.59.196.211),它返回了 stackoverflow.com,但我输入了 Google 的一个 IP 地址 (210.55.180.158),它返回了 cache.googlevideo.com(所有结果,而不仅仅是第一个).

                  I'm not sure if this is the best way to do this, but it works for me, mostly. I put in StackOverflow's IP addresses (69.59.196.211) and it gave me back stackoverflow.com, but I put in one of Google's IP addresses (210.55.180.158) and it gave me back cache.googlevideo.com (for all results, not just the first one).

                  int error;
                  struct addrinfo *results = NULL;
                  
                  error = getaddrinfo("69.59.196.211", NULL, NULL, &results);
                  if (error != 0)
                  {
                      NSLog (@"Could not get any info for the address");
                      return; // or exit(1);
                  }
                  
                  for (struct addrinfo *r = results; r; r = r->ai_next)
                  {
                      char hostname[NI_MAXHOST] = {0};
                      error = getnameinfo(r->ai_addr, r->ai_addrlen, hostname, sizeof hostname, NULL, 0 , 0);
                      if (error != 0)
                      {
                          continue; // try next one
                      }
                      else
                      {
                          NSLog (@"Found hostname: %s", hostname);
                          break;
                      }
                  }
                  
                  freeaddrinfo(results);
                  

                  地址可以有多个名称,因此您可能不想停留在找到的第一个名称.

                  There can be multiple names for the address, so you might not want to stop at the first one you find.

                  这篇关于如何从Objective C中的域名获取IP地址的域名和IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Why does Objective-C use YES/NO macro convention instead of true/false?(为什么 Objective-C 使用 YES/NO 宏约定而不是 true/false?)
                  Is there any difference between bool, Boolean, and BOOL in Objective-C?(Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?)
                  BOOL to NSString(布尔到 NSString)
                  Set bool property of all objects in the array(设置数组中所有对象的布尔属性)
                  Is comparing a BOOL against YES#160;dangerous?(将 BOOL 与 YES 进行比较是否危险?)
                  Objective-C dictionary inserting a BOOL(插入 BOOL 的 Objective-C 字典)
                    <tbody id='WBwbG'></tbody>

                  <small id='WBwbG'></small><noframes id='WBwbG'>

                          <bdo id='WBwbG'></bdo><ul id='WBwbG'></ul>
                        • <tfoot id='WBwbG'></tfoot>
                          <i id='WBwbG'><tr id='WBwbG'><dt id='WBwbG'><q id='WBwbG'><span id='WBwbG'><b id='WBwbG'><form id='WBwbG'><ins id='WBwbG'></ins><ul id='WBwbG'></ul><sub id='WBwbG'></sub></form><legend id='WBwbG'></legend><bdo id='WBwbG'><pre id='WBwbG'><center id='WBwbG'></center></pre></bdo></b><th id='WBwbG'></th></span></q></dt></tr></i><div id='WBwbG'><tfoot id='WBwbG'></tfoot><dl id='WBwbG'><fieldset id='WBwbG'></fieldset></dl></div>

                        • <legend id='WBwbG'><style id='WBwbG'><dir id='WBwbG'><q id='WBwbG'></q></dir></style></legend>