1.这里的扫描怎么实现的先找一些luci代码,在openwrt21版本后,luci用js替换了lua写后台,先找一些代码路径
在openrwt15这部分代码是在这个目录下
feeds/luci/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_join.htm
里面包含了html和lua,我们看一些lua部分是怎么实现的,直接copy代码
#!/usr/bin/luadev = arg[1]
local sys = require "luci.sys"
local utl = require "luci.util"
local iw = luci.sys.wifi.getiwinfo(dev)function scanlist(times)local i, k, vlocal l = { }local s = { }for i = 1, times dofor k, v in ipairs(iw.scanlist or { }) doif not s[v.bssid] thenl[#l+1] = vs[v.bssid] = trueendendendreturn lendfunction format_wifi_encryption(info)if info.wep == true thenreturn "WEP"elseif info.wpa > 0 thenreturn string.format("Pairwise: %s / Group: %s >%s - %s",table.concat(info.pair_ciphers, ", "),table.concat(info.group_ciphers, ", "),(info.wpa == 3) and string.format("mixed WPA/WPA2")or (info.wpa == 2 and "WPA2" or "WPA"),table.concat(info.auth_suites, ", "))elseif info.enabled thenreturn unknownelsereturn openendendfor i, net in ipairs(scanlist(3)) donet.encryption = net.encryption or { }print("channel:",net.channel);print("ssid:",net.ssid);print("bssid:",net.bssid);print("Mode:",net.mode);wep=net.encryption.wep and 1 or 0print("Encryption:",format_wifi_encryption(net.encryption));print("");
end
使用方法:
root@OPENWRT:~# ./test.lua ra0
还有就是openwrt和Web服务器的交互,我们请求了Web服务器,它不是回josn格式或者什么xml格式数据,而是直接回给了我们html文件,我们可以通过抓包看到
这是我们的http get请求和得到下响应
把这个html直接用浏览器打开是这个样子,缺少了一些css这些样式的东西
openwrt21之后代码路径变为了如下:
feeds/luci/modules/luci-base/htdocs/luci-static/resources/network.js
feeds/luci/docs/jsapi/network.js.html
大概代码是这样子,看不懂,截取部分,用过调用ubus命令得到数据
*/getMeshID: function() {if (this.getMode() != 'mesh')return null;return this.ubus('net', 'config', 'mesh_id') || this.get('mesh_id');},/*** Get the configured BSSID of the wireless network.** @returns {null|string}* Returns the BSSID value or `null` if none has been specified.*/getBSSID: function() {return this.ubus('net', 'config', 'bssid') || this.get('bssid');},
类似这样:ubus call iwinfo info '{ "device": "wlan0" }'
2.虚拟机给路由器开发板传文件,确保虚拟机已安装ssh
scp + 虚拟机里面要传的文件 + 开发板用户名@开发板ip地址:开发板放文件的路劲
scp mongoose root@192.168.1.1:/bin