【问题标题】:Fetching IP address of router to which iPhone is connected获取 iPhone 连接的路由器的 IP 地址
【发布时间】:2011-09-25 16:44:10
【问题描述】:

我想获取我的 iPhone 无线连接到的路由器(WiFi 接入点)的 IP 地址。该代码仅提供设备的 IP 地址

谁能帮忙写一段代码?

【问题讨论】:

  • 你检查过this吗?可能会给你一些想法。

标签: iphone objective-c ios cocoa-touch ip-address


【解决方案1】:

只需复制粘贴此代码并运行,您将获得通过 IP 地址连接的所有 IP 地址。所需的框架是

  #import <sys/types.h>
  #import <arpa/inet.h>
  #import <netdb.h>

在viewdidload中复制粘贴这个

int i=0;
 while (i>254) {
                i++;
                NSString *address = [NSString stringWithFormat:@"192.168.1.%d",i];
            struct hostent *he;
            struct in_addr ipv4addr;

            inet_pton(AF_INET, [address UTF8String], &ipv4addr);
            he = gethostbyaddr(&ipv4addr, sizeof ipv4addr, AF_INET);
            if (he) {
                printf("Host name: %s\n", he->h_name);
                NSLog(@"%@",address);
                //    NSLog(@"%@",address);
            }
        }

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 2021-08-14
    • 2015-02-28
    • 1970-01-01
    相关资源
    最近更新 更多