获取WIFI的相关信息

 - (void)getWifiInfo
{
NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
if (!ifs) {
return ;
}
NSDictionary *info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info && [info count]) {
break;
}
}
NSLog(@"WIFI名称 %@ MAC地址 %@",info[@"SSID"],info[@"BSSID"]);
}

获取WIFI网关以及子网掩码,端口等信息

 - (NSMutableDictionary *)getLocalInfoForCurrentWiFi {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = ;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == ) {
// 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"]) {
//----192.168.1.255 广播地址
NSString *broadcast = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_dstaddr)->sin_addr)];
if (broadcast) {
[dict setObject:broadcast forKey:@"broadcast"];
}
NSLog(@"broadcast address--%@",broadcast);
//--192.168.1.106 本机地址
NSString *localIp = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
if (localIp) {
[dict setObject:localIp forKey:@"localIp"];
}
NSLog(@"local device ip--%@",localIp);
//--255.255.255.0 子网掩码地址
NSString *netmask = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr)];
if (netmask) {
[dict setObject:netmask forKey:@"netmask"];
}
NSLog(@"netmask--%@",netmask);
//--en0 端口地址
NSString *interface = [NSString stringWithUTF8String:temp_addr->ifa_name];
if (interface) {
[dict setObject:interface forKey:@"interface"];
}
NSLog(@"interface--%@",interface);
return dict;
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return dict;
}

wifi,网关相关标识的获取的更多相关文章

  1. 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素

    [源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...

  2. wifi测试相关(iwconfig,WPA Supplicant用法)

    iwconfig用法 1.打开无线网卡电源 iwconfig wlan0 txpower no 2.列出区域内的无线网络 iwconfig wlan0 scan 3.假设要连接到网络myhome(即e ...

  3. java nginx等代理或网关转发请求后获取客户端的ip地址,原理

    在没有网关或者反向代理软件情况下,java里获取客户端ip地址的方法是request.getRemoteAddr() 先解释下http协议和TCP协议: 网页默认是进行http连接了,http协议即超 ...

  4. Windows下查看自己电脑的网关mac以及手动获取新的地址

    场景:正在上班时,工作电脑突然无法连接网络了.查看配置发现DNS服务器地址被分配到了192.168.1.1,瞬间懵了? 过程:(1)进入cmd.使用ipconfig /all查看网关地址; (2)使用 ...

  5. 如何获取select中的value、text、index相关值 && 如何获取单选框中radio值 && 触发事件 && radio 默认选中

    如何获取select中的value.text.index相关值 select还是比较常用的一个标签,如何获取其中的内容呢? 如下所示: <select id="select" ...

  6. 利用WiFi Pineapple Nano渗透客户端获取SHELL

    前言: 前两篇文章介绍了The WiFi Pineapple Nano设备的一些主要功能模块,例如PineAP.SSLsplit和Ettercap等.今天给大家实际场景演示下如何利用Pineapple ...

  7. 微服务时代之网关相关技术选型及部署(nacos+gateway)

    1.场景描述 因要用到微服务,关于注册中心这块,与同事在技术原型上做了讨论,初步定的方案是使用:阿里巴巴的nacos+springcloud gateway,下面表格是同事整理的注册中心对比,以前用的 ...

  8. session,cookie,sessionStorage,localStorage的相关设置以及获取删除

    一.cookie 什么是 Cookie? "cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie.你可以使用 JavaScrip ...

  9. Java基础 - Date的相关使用(获取系统当前时间)

    前言: 在日常Java开发中,常常会使用到Date的相关操作,如:获取当前系统时间.获取当前时间戳.时间戳按指定格式转换成时间等.以前用到的时候,大部分是去网上找,但事后又很快忘记.现为方便自己今后查 ...

随机推荐

  1. 【Shell脚本】怎样表示一个for循环

    [Shell脚本]怎样表示一个for循环 在此说一下我常用的两个结构: 1. for i in $(seq 1 100); do         echo $i done 2. for (( i = ...

  2. SharePoint Style Library的权限问题

    Style Library是属于site collection级别的. 所以如果在某一个site中直接给某个用户设置了比如Full control的权限,这个权限信息并不会自动进入Style Libr ...

  3. mysql存储过程详细教程

    记录mysql存储过程中的关键语法:DELIMITER //  声明语句结束符,用于区分;CREATE PROCEDURE demo_in_parameter(IN p_in int)  声明存储过程 ...

  4. protobuf框架简介

                         protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.google 提供了三种语言的实现:java.c+ ...

  5. eclipse:不能在tomcat里添加一个项目的解决方法

    Cannot add a project to a tomcat server in eclipse You didn't create your project as "Dynamic W ...

  6. json文本装换为JSONArray

    package com.beijxing.TestMain; import java.io.File; import java.io.IOException; import org.apache.co ...

  7. centos 安装 nginx

    采用版本 nginx-1.9.8.tar.gz yum -y install pcre-devel yum -y install openssl openssl-devel tar –zxvf ngi ...

  8. C# IntPtr转换为Byte[]

    [DllImport("OpenNetStream.dll")] public static extern int OpenSDK_Data_GetDevList(IntPtr s ...

  9. Storyboard中segue(转场)使用

    源引:http://www.2cto.com/kf/201210/161737.html 一.视图切换类型介绍在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,s ...

  10. git入门操作命令(转载)

    以下为git环境搭建: 先建用户-->建组-->用户添加到组   新建项目,命名空间选择组 项目建完后,会分配远端地址. 然后本地配置好远端地址后,提交代码.   设置用户,邮箱 git ...