iphone获取当前流量信息
通过读取系统网络接口信息,获取当前iphone设备的流量相关信息,统计的是上次开机至今的流量信息.
代码 悦德财富:https://yuedecaifu.com
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
-( void )checkNetworkflow{ struct ifaddrs *ifa_list = 0, *ifa; if (getifaddrs(&ifa_list) == -1) { return ; } uint32_t iBytes = 0; uint32_t oBytes = 0; uint32_t allFlow = 0; uint32_t wifiIBytes = 0; uint32_t wifiOBytes = 0; uint32_t wifiFlow = 0; uint32_t wwanIBytes = 0; uint32_t wwanOBytes = 0; uint32_t wwanFlow = 0; struct timeval time ; for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) { if (AF_LINK != ifa->ifa_addr->sa_family) continue ; if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING)) continue ; if (ifa->ifa_data == 0) continue ; // Not a loopback device. // network flow if ( strncmp (ifa->ifa_name, "lo" , 2)) { struct if_data *if_data = ( struct if_data *)ifa->ifa_data; iBytes += if_data->ifi_ibytes; oBytes += if_data->ifi_obytes; allFlow = iBytes + oBytes; time = if_data->ifi_lastchange; } //wifi flow if (! strcmp (ifa->ifa_name, "en0" )) { struct if_data *if_data = ( struct if_data *)ifa->ifa_data; wifiIBytes += if_data->ifi_ibytes; wifiOBytes += if_data->ifi_obytes; wifiFlow = wifiIBytes + wifiOBytes; } //3G and gprs flow if (! strcmp (ifa->ifa_name, "pdp_ip0" )) { struct if_data *if_data = ( struct if_data *)ifa->ifa_data; wwanIBytes += if_data->ifi_ibytes; wwanOBytes += if_data->ifi_obytes; wwanFlow = wwanIBytes + wwanOBytes; } } freeifaddrs(ifa_list); changeTime.text = [NSString stringWithFormat:@ "%s" , ctime (& time )]; receivedBytes.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,iBytes]]; sentBytes.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,oBytes]]; networkFlow.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,allFlow]]; wifiReceived.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,wifiIBytes]]; wifiSent.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,wifiOBytes]]; wifiBytes.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,wifiFlow]]; wwanReceived.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,wwanIBytes]]; wwanSent.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,wwanOBytes]]; wwanBytes.text = [self bytesToAvaiUnit:[NSString stringWithFormat:@ "%u" ,wwanFlow]]; } |
iphone获取当前流量信息的更多相关文章
- iphone获取sim卡信息
/* iphone获取sim卡信息 1.加入一个Framework(CoreTelephony.framework). 2.引入头文件 #import <CoreTelephony/CTTele ...
- iphone获取当前磁盘信息
获取iphone磁盘总大小.已使用空间.空闲空间 [代码]悦德财富:https://www.yuedecaifu.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- 获取应用程序信息.h
//// 获取应用程序信息.h// IOS笔记// 一般会用来判断是否有新版本.是否需要强制更新 iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中ta ...
- JavaScript获取访问设备信息
<html xmlns=http://www.w3.org/1999/xhtml> <head> <title>JavaScript获取访问设备信息</tit ...
- sql 2012中获取表的信息,包含字段的描述
1.获取数据库中的表 select name from sysobjects where type='U' 2.获取表字段(此处是Route表) Select name from syscolumns ...
- ThinPHP命名空间,连接数据库是要修改的配置文件,Model数据模型层,跨控制器调用,如何获取系统常量信息,
一.命名空间(主要是为了实现自动加载类) *命名空间(相当于虚拟的目录),为了让类有一个统一的文件夹来管理(可以自动加载'类'),每个文件都要有命名空间*tp如何做命名空间:*TP框架下有一个初始命名 ...
- PHP获取当前服务器信息的基本语句
下面是PHP获取当前服务器信息的基本语句. PHP程式版本: <?PHP echo PHP_VERSION; ?> ZEND版本: <?PHP echo zend_version() ...
- C# 获取 mp3文件信息
C# 获取 mp3文件信息[包括:文件大小.歌曲长度.歌手.专辑] 第一种方式:[代码已验证] // http://bbs.csdn.net/topics/390392612 string fil ...
- Linux sysinfo获取系统相关信息
Linux中,可以用sysinfo来获取系统相关信息. #include <stdio.h> #include <stdlib.h> #include <errno.h& ...
随机推荐
- opencl初探-sobel检测
sobel检测的C版本,neon和GPU的时间比较. Platform: LG G3, Adreno 330 ,img size 3264x2448 sobel: C code neon GPU 73 ...
- SSH2 架构常用注解
1. @Repository 将 DAO 类声明为 Bean 2.@Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可以作用在任何层次. 3.@Service 通常作用在业务层 ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 增、查、改、删操作
Create, Read, Update, and Delete operations¶ 5 of 5 people found this helpful By Tom Dykstra The Con ...
- Eclipse中Ant的配置与测试 转
欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...
- controller 监控Unix性能信息
linux系统需要有RPC(Remote Procedure Call Protocol),远程过程调用协议,通过安装rpc.rstatd程序,启动其服务,就可以给远程机器提供信息,即Lr可以获取到该 ...
- java中运算符的解析和计算
package com.LBH; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import j ...
- 【数位统计】之【spoj1433 KPSUM】
[spoj1433]KPSUM 来源 高逸涵<数位计数问题解法研究> 由于自己的数位计数类的问题实在太差了,所以把例2用markdown抄写并补充了一遍. 题意 将写在纸上,然后在相邻的数 ...
- C#高级知识点概要(2) - 线程和并发
原文地址:http://www.cnblogs.com/Leo_wl/p/4192935.html 我也想过跳过C#高级知识点概要直接讲MVC,但经过前思后想,还是觉得有必要讲的.我希望通过自己的经验 ...
- 初学java之(盒子分布)
import javax.swing.*; import java.awt.*; class WinGrid extends JFrame { Box basebox , boxv1,boxv2; p ...
- 《JavaScript权威指南》读书笔记(二)
日期:2015-12-04 js 的原型::闭包:闭包这是个相当复杂的东西...现在初步理解: http://segmentfault.com/a/1190000000652891 闭包有 ...