【问题标题】:Resolve NetBIOS name on iOS解析 iOS 上的 NetBIOS 名称
【发布时间】:2017-01-28 02:47:28
【问题描述】:

iOS 上有没有办法使用 IP 地址解析 NetBIOS 名称?

可以在 Mac 上使用 终端命令解析 NetBIOS 名称:

smbutil -v 状态 -ae

smbutil 是开源的,所以你可以在这里找到它: http://www.apple.com/opensource/ -> http://opensource.apple.com//source/smb/

在 GitHub 上也是如此: https://github.com/unofficial-opensource-apple/smb

但该实用程序广泛使用私有和 Mac OS 特定的框架,因此 Xcode 甚至无法编译 iOS 的源代码。

【问题讨论】:

标签: ios network-programming netbios


【解决方案1】:

我认为您只需要进行反向 DNS 查找,gethostbyaddr,因为它看起来像 DNS,gethostbyname,是唯一用于从 NetBios 名称到 IP 的东西。

查看Apple的源代码,'status'模式下的smbutil应用程序首先调用'nb_resolvehost',它只是使用'gethostbyname'从NetBios名称中获取IP地址。 'gethostbyname' 在后台使用 DNS:

nb_resolvehost_in(const char *name, struct sockaddr **dest)
{
    struct hostent* h;
    struct sockaddr_in *sinp;
    int len;

    h = gethostbyname(name);
    if (!h) {
        warnx("can't get server address `%s': ", name);
        herror(NULL);
        return ENETDOWN;
    }
    if (h->h_addrtype != AF_INET) {
        warnx("address for `%s' is not in the AF_INET family", name);
        return EAFNOSUPPORT;
    }
    if (h->h_length != 4) {
        warnx("address for `%s' has invalid length", name);
        return EAFNOSUPPORT;
    }
    len = sizeof(struct sockaddr_in);
    sinp = malloc(len);
    if (sinp == NULL)
        return ENOMEM;
    bzero(sinp, len);
    sinp->sin_len = len;
    sinp->sin_family = h->h_addrtype;
    memcpy(&sinp->sin_addr.s_addr, h->h_addr, 4);
    sinp->sin_port = htons(SMB_TCP_PORT);
    *dest = (struct sockaddr*)sinp;
    return 0;
}

在此调用之后,“smbutil status”然后使用函数“nbns_getnodestatus”向 SMB 端口上先前给定的 IP 地址发送某种 SMB 查询。从此查询中,该命令获取 Workgroup 和 Servername(不确定这是指哪个服务器)。

【讨论】:

  • 你能看看这个thread吗?您知道如何解决从连接的 wi-fi 的网络扫描中获取主机名的问题吗? App Store 上的其他应用如 Fing、Net Analyzer 都可以获取主机名。
  • @ChintanShah 如果您已经在枚举 IP 地址,则可以将地址反向 DNS,如 here 所示。不过一般警告,枚举网络可能会将您的应用程序标记为恶意软件,可能需要查看多播。
猜你喜欢
  • 2011-06-12
  • 1970-01-01
  • 2018-09-09
  • 2021-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
相关资源
最近更新 更多