简体   繁体   中英

Fetching IP address of router to which iPhone is connected

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?

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>

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

The router for your access point should always be the default route, so the problem then becomes, how do you find that default route IP address?

This article is a bit old now, but provides some sample code. Haven't tried it myself I'm afraid, but probably worth you giving it a try.

How can I determine the default gateway on iPhone?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM