获取WIFI的SSID和本机IP
1.获取WIFI的SSID
引入库

#import <SystemConfiguration/CaptiveNetwork.h>
.....
.....
// WIFI的名字
+ (NSString *)getWifiSSID
{
NSArray *ifs = (__bridge id)CNCopySupportedInterfaces();
id info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info && [info count]) {
break;
}
}
NSDictionary *dctySSID = (NSDictionary *)info;
NSString *ssid = [[dctySSID objectForKey:@"SSID"] lowercaseString];
return ssid;
}
2.获取本机IP
#import <ifaddrs.h>
#import <arpa/inet.h>
.....
.....
// Get IP Address
- (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;
}
获取WIFI的SSID和本机IP的更多相关文章
- 关于如何获取项目所部署的本机IP和端口的问题
关于如何获取项目所部署的本机IP和端口的问题 今天在写一个需求的时候碰到一个不常见的问题,在没有继承或者实现服务器提供的接口或者实现类的时候,比如说部署在tomacat上,某个类不去继承servelt ...
- iOS 12中获取WiFi的SSID
开始搞智能家居,wifi获取不到了?? 小插曲 旧方法失效,19-12-15更新,ios13开始需要请求定位信息 SSID全称Service Set IDentifier, 即Wifi网络的公开名称. ...
- 获取Wi-Fi的SSID
前几天做项目的时候,碰到一个问题,获取wifi的SSID,其实就是获取Wi-Fi的名字 iOS12以前 在iOS13之前获取wifi的SSID很简单,苹果提供了接口CNCopyCurrentNetwo ...
- iOS 12中无法获取WiFi的SSID了?
1.现象描述 2018年苹果升级iOS12之后,没有办法获取wifi名称等信息. 2.获取wifi信息 2.1 获取代码 /************ 控制器的view 加载完毕 的时候调用 ***** ...
- IOS 获取wifi的SSID
#import <SystemConfiguration/CaptiveNetwork.h> - (NSString *)currentWifiSSID { // Does not wor ...
- 【iOS开发】获取wifi的SSID
#import <SystemConfiguration/CaptiveNetwork.h> NSArray *ifs = (__bridge_transfer id)CNCopySupp ...
- 如何获取wifi名称(SSID)
@import SystemConfiguration.CaptiveNetwork; /** Returns first non-empty SSID network info dictionary ...
- java获取windows和linux下本机ip通用方法
public InetAddress getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6) throws SocketE ...
- 获取本机IP地址
这里有两种方法: //获取本机IP - (NSString *)localIPAddress { NSString *localIP = nil; struct ifaddrs *addrs; ) { ...
随机推荐
- 用iptables 实现本地端口转发
设定本机2121端口转发到21端口 iptables -t nat -A PREROUTING -p tcp -i eth0 -d -j DNAT --to iptables -t nat -I PO ...
- Apache RewriteHTTPToHTTPS
HTTP to HTTPS Scenario : You want to force people coming to your site to use HTTPS. Either for the e ...
- 最新原创:Power8伴随云计算横空出世
Power8伴随云计算横空出世 自从IBM将并不赚钱的x86服务器业务转手给联想之后,从此IBM便开始了硬件转型的新里程碑.伴随此事继续发酵的还有Power System Linux落户北京,从此IB ...
- TCP、UDP、IP 协议分析
http://rabbit.xttc.edu.cn/rabbit/htm/artical/201091145609.shtml http://bhsc881114.github.io/2015/06 ...
- sqlserver如何关闭死锁进程.
1.首先我们需要判断是哪个用户锁住了哪张表. --查询被锁表 select request_session_id spid,OBJECT_NAME(resource_associated_entity ...
- PIC32MZ tutorial -- UART Communication
At this moment, I accomplish the interface of UART communication for PIC32MZ EC Starter Kit. This in ...
- Leetcode3:Longest Substring Without Repeating Characters@Python
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- “不是有效WIN32程序”
写了个控制台,放到服务器上面运行,运行失败,出现"不是有效win32程序" 不知道原因. 猜测: 1.程序只支持64位的处理器,修改了项目的属性,发现支持any cpu.排除 2. ...
- 金山云—ubuntu-web服务器完整部署笔记
金山云-ubuntu-web (jdk环境配置+tomcat配置+nginx反向代理)服务器完整部署文档第一步:挂载数据盘 参考金山云帮助文档 http://www.ksyun.com/doc/art ...
- 删除注释云平台JS,加快DISCUZ访问
对于港台或者美国服务器的用户可能感觉访问慢,页面卡:实际上是由于 http://www.discuzlab.com/discuz.gtimg.cn/cloud/scripts/discuz_tip ...