Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

objective c - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
", he->h_name);
                NSLog(@"%@",address);
                //    NSLog(@"%@",address);
            }
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...