iPhone设备当前IP和SSID的获取
#import <Foundation/Foundation.h>
typedef void(^Complation)(NSString *res);
@interface WIFIManager : NSObject
+ (WIFIManager* )shareSington ;
- (void)localWIFIName:(Complation) complation;
- (void)localWiFiIPAddress:(Complation) complation;
@end
// 实现
#import "WIFIManager.h"
#import <SystemConfiguration/CaptiveNetwork.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#include <ifaddrs.h>
#import <dlfcn.h>
@implementation WIFIManager
+ (WIFIManager *)sharedInstance
{
static WIFIManager* manager = nil;
static dispatch_once_t once ;
dispatch_once(&once, ^{
manager = [[WIFIManager alloc] init];
});
return manager ;
}
- (void)localWIFIName:(Complation)complation
{
dispatch_queue_t queue=dispatch_queue_create("WIFI_NAME", NULL);
dispatch_async(queue, ^{
id obj = [self fetchSSIDInfo];
dispatch_async(dispatch_get_main_queue(), ^{
if ([obj isKindOfClass:[NSDictionary class]]) {
NSDictionary *dic = obj;
complation([dic objectForKey:@"SSID"]);
}else
{
complation(nil);
}
});
});
}
- (void)localWiFiIPAddress:(Complation)complation
{
dispatch_queue_t queue=dispatch_queue_create("WIFI_IP", NULL);
dispatch_async(queue, ^{
NSString *ip = [self localWiFiIPAddress];
dispatch_async(dispatch_get_main_queue(), ^{
complation(ip);
});
});
}
- (NSString *)localWiFiIPAddress
{
BOOL success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0)
{
NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
if ([name isEqualToString:@"en0"]) // Wi-Fi adapter
return [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return nil;
}
- (id)fetchSSIDInfo {
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
id info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info && [info count]) { break; }
}
return info;
}
@end
iPhone设备当前IP和SSID的获取的更多相关文章
- ios7 以后准确获取iphone设备的MAC(物理地址)
通过参考 钉钉 项目,知道是通过wifi拿到路由的MAC地址.那么可不可以拿到iphone 设备的MAC 地址呢? 经过一番搜索,发现所有文章都是针对 ios 7 以前 可以拿到. 而且方法也都是同一 ...
- C#获取设备的IP和Mac类
/// <summary> /// 此类用于获得设备的Ip和Mac /// </summary> public class Mac { [DllImport("Iph ...
- 关于iPhone设备不同显示尺寸适配的一些方法
关于iPhone设备不同显示尺寸适配的一些方法 ------关于适配的理解------ 1.什么是适配? 适配是对不同硬件和系统软件的适应,硬件包括屏幕显示,处理器,内存等等(目前主要是屏幕适配, ...
- ios5和ios6横竖屏支持及ipad和iphone设备的判断
ios5和ios6横竖屏支持及ipad和iphone设备的判断 判断是ipad还是iphone设备.此定义在PayViewControllerDemo-Prefix.pch 定义如下: #define ...
- Android便携式热点的开启状态检测和SSID的获取
WIFI热点的开启状态和开启后的SSID如何获取呢? 打开WifiManager.java源码,可找到 getWifiApState() 方法,惊喜的发现直接调用这个方法就能获取到热点的状态,然而在调 ...
- [原创]K8Cscan插件之Cisco思科设备扫描(IP、设备型号、主机名、Boot、硬件版本)
[原创]K8 Cscan 大型内网渗透自定义扫描器 https://www.cnblogs.com/k8gege/p/10519321.html Cscan简介:何为自定义扫描器?其实也是插件化,但C ...
- iPhone设备及屏幕适配
// // Common.h // 微信 // // #ifndef Common_h #define Common_h // iPhone设备及屏幕适配 //4的设备 #define KDevice ...
- 在局域网中查找特定设备的 IP
如何查找特定设备的 IP 有几种方法在局域网中找到某个设备(设为设备 A)的 IP 地址: 在设备 A 上运行一段程序,该程序每隔一段时间向局域网中发送广播包(UDP 广播包),(设备 B)上运行另一 ...
- 同一域名对应多个IP时,PHP获取远程网页内容的函数
同一域名对应多个IP时,PHP获取远程网页内容的函数 [文章作者:张宴 本文版本:v1.0 最后修改:2008.12.15 转载请注明原文链接:http://blog.zyan.cc/post/389 ...
随机推荐
- JQuery之操作array
1:split 函数将字符串按某个字符分割,将分割后的结果存入字符串数组中 function SplitUsersInformation(users) { var usersArray = users ...
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- 【Swift】学习笔记(八)——类和结构体
1.类和结构体的定义 <pre name="code" class="html">struct Resolution { var width = 0 ...
- 懒人学习automake, Makefile.am,configure.ac
已经存在Makefile.am,如何生成Makefile? 步骤: [root@localhost hello]# autoscan .///在当前文件夹中搜索 [root@localhost hel ...
- JSP-Runoob:JSP 链接数据库
ylbtech-JSP-Runoob:JSP 链接数据库 1.返回顶部 1. JSP 连接数据库 本教程假定您已经了解了 JDBC 应用程序的工作方式.在您开始学习 JSP 数据库访问之前,请访问 J ...
- Flink编程练习
目录 1.wordcount 2.双流警报EventTime 3.持续计数stateful + timer + SideOutputs 4.一定时间范围内的极值windowfunction + che ...
- Speed Limit
http://poj.org/problem?id=2017 #include<stdio.h> int main() { int n,mile,hour; ) { ,h = ; whil ...
- Java Socket编程 深入讲解?你之前真的学懂了吗
很多人学习Socket往往会碰到这样哪样的问题,可以看看下面,加深理解.能看懂多少看懂多少. Socket是Java网络编程的基础,了解还是有好处的,这篇文章主要讲解Socket的基础编程.Socke ...
- ACM_Reverse Bits(反转二进制)
Reverse Bits Time Limit: 2000/1000ms (Java/Others) Problem Description: Reverse bits of a given 32 b ...
- Application、Activity Stack 和 Task的区别
Application类 Application和Activity,Service一样是Android框架的一个系统组件,当Android程序启动时系统会创建一个Application对象,用来存储系 ...