IOS 获取手机ip地址

#include <ifaddrs.h>

#include <arpa/inet.h>

- (NSString *)getIPAddress

{

    

    NSString *address = @"error";

    struct ifaddrs *interfaces = NULL;

    struct ifaddrs *temp_addr = NULL;

    int success = 0;

    

    // retrieve the current interfaces - returns 0 on success

    success = getifaddrs(&interfaces);

    if (success == 0) {

        // Loop through linked list of interfaces

        temp_addr = interfaces;

        while (temp_addr != NULL) {

            if( temp_addr->ifa_addr->sa_family == AF_INET) {

                // Check if interface is en0 which is the wifi connection on the iPhone

                if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {

                    // Get NSString from C String

                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];

                }

            }

            

            temp_addr = temp_addr->ifa_next;

        }

    }

    

    // Free memory

    freeifaddrs(interfaces);

    

    return address;

}

IOS 获取手机ip地址

时间: 2024-10-23 17:48:47

IOS 获取手机ip地址的相关文章

ios获取局域网IP地址

#include <arpa/inet.h> #include <net/if.h> #include <ifaddrs.h> - (NSString *)localIPAddress { NSString *localIP = nil; struct ifaddrs *addrs; if (getifaddrs(&addrs)==0) { const struct ifaddrs *cursor = addrs; while (cursor != NULL)

转载-iOS获取设备IP地址

iOS获取设备IP地址 代码如下: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 #import <ifaddrs.h>#import <arpa/inet.h>#

iOS 获取手机ip 《转/复制粘贴》

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #import <ifaddrs.h> #import <arpa/inet.h> // Get IP Address - (NSString *)getIPAddress {         NSString *address = @"error";     struct ifaddrs *interfaces = N

iOS 获取手机IP

引入头文件 #include <ifaddrs.h> #include <arpa/inet.h> - (NSString *)getIPAddress {        NSString *address = @"error";    struct ifaddrs *interfaces = NULL;    struct ifaddrs *temp_addr = NULL;    int success = 0;    success = getifaddr

IOS获取本地IP地址以及网关IP地址

route.h如下: /* * Copyright (c) 2000-2008 Apple Inc. All rights reserved. * * @[email protected] * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Versio

java获取客户端IP地址和MAC地址

最近项目中要获得客户端的mac地址.服务端是移植的centos系统,arm架构的盒子.客户端是手机和移动设备.(其它场景应该也是类似的) 首先要获得ip地址: 根据客户端的http请求,利用request.getRemoteAddr()获取客户端Ip地址.在局域网内getRemoteAddr()和getRemoteHost()获得的结果相同.request.getRemoteAddr()是获得客户端的ip地址 .getRemoteHost()是获得客户端的主机名 .在有些场景中,可能有Squid

获取代理IP地址

今天在开源中国上看到有个有写了个小程序,用来获取代理IP地址.用的beautifulsoup. 自己动手用正则重写了一下. #!/usr/bin/python import requests import re pattern=re.compile(r'(\d+)\D(\d+)\D(\d+)\D(\d+)\D(\d+)') headers={'Host':"www.ip-adress.com", 'User-Agent':"Mozilla/5.0 (Windows NT 6.

Flask框架获取用户IP地址的方法

本文实例讲述了python使用Flask框架获取用户IP地址的方法.分享给大家供大家参考.具体如下: 下面的代码包含了html页面和python代码,非常详细,如果你正使用Flask,也可以学习一下最基本的Flask使用方法. python代码如下: from flask import Flask, render_template, request # Initialize the Flask application app = Flask(__name__) # Default route,

再论 ASP.NET 中获取客户端IP地址

说到IP获取无非是我们常见的以下几种方式,但是具体获取的值具体区别在哪?网上不乏相关文章,说的也是很详细,但是真正使用起来,还有很多不太对的地方.IP在不同系统中,应用相当广泛,常见的日志记录.广告分区域投放等. 1: HttpContext.Current.Request.ServerVariables["HTTP_VIA"]; 2: HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"