获取iPhone连接的路由器的IP地址 [英] Fetching IP address of router to which iPhone is connected

查看:171
本文介绍了获取iPhone连接的路由器的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要撷取iPhone无线连接的路由器(WiFi存取点)的IP位址。代码只提供设备的IP地址

I want to fetch the IP address of the router (WiFi access point) to which my iPhone is connected wirelessly. The code gives only the IP address of the device

任何人都可以帮助一段代码?

Can anyone help with a piece of code?

推荐答案

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

Just Copy paste this code and run you will get all ip address that connected through ip address. Required Frameworks are

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

在viewdidload副本中粘贴

in viewdidload copy paste this

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);
            }
        }

这篇关于获取iPhone连接的路由器的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆