找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 5285|回复: 9

openwrt实时显示在线客户端是怎么做到的?附上相关源码,大佬看看

[复制链接]
发表于 2018-12-11 11:14 | 显示全部楼层 |阅读模式
本帖最后由 白云纷飞 于 2018-12-11 15:20 编辑

找到一个相关的内容,能力有限,已经七八年没接触编程了,有能力刚好又有需求的大佬看看吧。。。
【智能路由器】设备流量、网速统计及上下线提醒(基于netfilter编程)
https://blog.csdn.net/u012819339/article/details/50513387
还有一个源码链接https://blog.csdn.net/yuyu0602/article/details/81093889
https://pan.baidu.com/s/1GuyhMbsdTCEjbGVp00hjFA

斐讯固件的终端管理可以做到客户端上线下线实时刷新,查询了下资料,openwrt通过
/proc/net/arp 可以查看在线客户端,但是这个是30秒刷新一次,做不到斐讯那样的实时刷新,查看了下斐讯的代码,看得一脸懵逼,有没有大佬指导一下?






我的恩山、我的无线 The best wifi forum is right here.
发表于 2018-12-11 11:19 | 显示全部楼层
把代码贴出来 让大家一起研究一下

点评

主要代码如下  详情 回复 发表于 2018-12-11 11:27
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2018-12-11 11:20 | 显示全部楼层
DC1  R1 W1等 基本都残废了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2018-12-11 11:23 来自手机 | 显示全部楼层
无线是有状态的可以做到,以太网就不行了

点评

[attachimg]259197[/attachimg] 斐讯这个倒是有线的也可以,估计从底层代码实现的  详情 回复 发表于 2018-12-11 11:32
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-11 11:27 | 显示全部楼层
本帖最后由 白云纷飞 于 2018-12-11 11:29 编辑
qfnuzlr 发表于 2018-12-11 11:19
把代码贴出来 让大家一起研究一下



还有个so文件,估计处理代码都在里面


主要代码如下
  1. --[[
  2. **********************************************************************************
  3. * Copyright (c) 2016 Shanghai Feixun Communication Co.,Ltd.
  4. * All rights reserved.
  5. *
  6. * FILE NAME  :   device_mng_plt.lua
  7. * VERSION    :   1.0
  8. * DESCRIPTION:   平台相关的终端管理回调函数
  9. *
  10. * AUTHOR     :   LiGuanghua <liguanghua@phicomm.com>
  11. * CREATE DATE:   12/12/2016
  12. *
  13. * HISTORY    :
  14. * 01   12/12/2016  LiGuanghua     Create.
  15. * 02   07/12/2017  MengQingru     Modified.剥离平台无关代码
  16. **********************************************************************************
  17. --]]

  18. local err = require("luci.phicomm.error")
  19. local dbg = require("luci.phicomm.debug")

  20. module("luci.controller.admin.device_mng_plt", package.seeall)

  21. function index()

  22. end

  23. function data_get_convert(src, key)
  24.         local cjson = require("cjson")
  25.         local data = cjson.decode(src)

  26.         local obj = {}
  27.         local t_src = {}

  28.         for j=1, #(data.Objects) do
  29.                 local t_key = {}

  30.                 -- convert src data to json data
  31.                 for i, w in ipairs(data.Objects[j].Param) do
  32.                         t_src[w.ParamName] = w.ParamValue
  33.                 end

  34.                 if t_src['alias'] ~= "" then
  35.                         t_src['hostname'] = t_src['alias']
  36.                 end

  37.                 for k, v in pairs(key) do
  38.                         t_key[k] = t_src[v]
  39.                 end

  40.                 t_key["id"] = data.Objects[j].ObjName
  41.                 obj[j] = t_key
  42.         end

  43.         return obj
  44. end

  45. function get_client_list_plt(args, uciname, secname)
  46.         local clients_obj = [[{
  47.                 "Device.Clients.Client" : null}]]

  48.         local clients_key = {
  49.                 id = "",
  50.                 mac = "MAC",
  51.                 ip = "IP",
  52.                 name = "hostname",
  53.                 brand = "brand",
  54.                 internet_enable = "acc_enable",
  55.                 upload_limit = "tx_speed",
  56.                 download_limit = "rx_speed",
  57.                 upload_speed = "rt_tx_rate",
  58.                 download_speed = "rt_rx_rate",
  59.                 online_status = "is_online",
  60.                 online_time = "online_period",
  61.                 device_type = "if_type"
  62.         }

  63.         local errcode, result, data
  64.         local libphi_cgi = require("luci.adapter.libphi_cgi")

  65.         errcode, data = libphi_cgi.get_conf(clients_obj)
  66.         if data == nil then
  67.                 return errcode, data
  68.         end

  69.         if errcode == err.E_NONE then
  70.                 -- convert cgi data to ui data
  71.                 result = data_get_convert(data, clients_key)
  72.         end

  73.         return errcode,  result

  74. end

  75. function get_device_num_plt(args, uciname, secname)
  76.         local online_num = {}
  77.         local file = io.open("/tmp/online_num", "r")
  78.         if file ~= nil then
  79.                 local data = file:read("*a")
  80.                 local colon_index = string.find(data, ':')
  81.                 local bar_index = string.find(data, '|')
  82.                 local minus_index = string.find(data, '-')
  83.                 if colon_index and bar_index and minus_index then
  84.                         online_num.online_lan = string.sub(data, 1, colon_index-1)
  85.                         online_num.online_24G = string.sub(data, colon_index+1, bar_index-1)
  86.                         online_num.online_5G = string.sub(data, bar_index+1, minus_index-1)
  87.                         online_num.online_guest = string.sub(data, minus_index+1, string.len(data)-1)
  88.                 else
  89.                         online_num.online_lan = 0
  90.                         online_num.online_24G = 0
  91.                         online_num.online_5G = 0
  92.                         online_num.online_guest = 0
  93.                 end
  94.                 file:close()
  95.         end
  96.         return err.E_NONE, online_num
  97. end
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-11 11:32 | 显示全部楼层
LGA1150 发表于 2018-12-11 11:23
无线是有状态的可以做到,以太网就不行了


斐讯这个倒是有线的也可以,估计从底层代码实现的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

点评

轮询(polling)呗,频率自己定  详情 回复 发表于 2018-12-11 13:37
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2018-12-11 13:03 | 显示全部楼层
openwrt可以实时检测无线设备(利用/etc/hotplug/wifi。部分可能由于驱动等问题无效,如k2p)。以太网的没研究。看代码貌似这里不是主要的
local clients_obj = [[{"Device.Clients.Client" : null}]]
local libphi_cgi = require("luci.adapter.libphi_cgi")
errcode, data = libphi_cgi.get_conf(clients_obj)
data里面包含了设备的信息
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2018-12-11 13:37 来自手机 | 显示全部楼层
白云纷飞 发表于 2018-12-11 11:32
斐讯这个倒是有线的也可以,估计从底层代码实现的

轮询(polling)呗,频率自己定
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-11 15:00 | 显示全部楼层
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-13 10:56 | 显示全部楼层
源码涉及到了内核模块编译,源代码是基于内核2.x编写的,linux内核升级从不考虑代码兼容性,在4.x内核上编译报错'struct nf_hook_ops' has no member named 'list',搜索了一圈也没找到相应的解决办法。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-3-28 20:11

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表