Skip to content

Contents

安装依赖库

vlan

arm芯片需要编译

sudo apt-get install vlan
sudo modprobe 8021q

加载内核模块:sudo modprobe 8021q 查看模块加载成功与否:lsmod |grep ‘8021q’

参考 https://wiki.ubuntu.com/vlan

8021q源代码

https://github.com/torvalds/linux/tree/master/net/8021q

jq

sudo apt-get install jq

arm芯片 ubuntu可以直接apt-get install

jq源代码

https://jqlang.github.io/jq/download/

rndis

<*> USB Gadget Drivers
<*> USB functions configurable through configfs
<*> Ethernet Gadget (with CDC Ethernet support)
[*] RNDIS support (NEW)

lsusb核验Linux-USB Ethernet/RNDIS Gadget

gadget源代码

https://www.kernel.org/doc/html/v4.17/driver-api/usb/gadget.html http://www.linux-usb.org/gadget/ http://www.linux-usb.org/usbnet/

curl

curl源代码


准备配置文件 依次按照顺序来操作

/etc/nhxmac

  • mac地址存放文件,此mac地址为:ap/ac显示客户端mac地址
5C:B1:5F:C0:00:00

/etc/udev/rules.d/80-net-setup-link.rules

  • 批量处理:放入开机脚本
  • 临时测试:sh /etc/udev/rules.d/80-net-setup-link.rules
# !/bin/sh
mac=$(cat /etc/nhxmac)
ifconfig usb0 down
ifconfig usb0 hw ether $mac
ifconfig usb0 up
# dhclient usb0 &
vconfig add usb0 2222
ifconfig usb0.2222 down
ifconfig usb0.2222 188.168.1.253 netmask 255.255.255.0
ifconfig usb0.2222 up

nhxusb0mac.sh

  • 第一次对接网卡api 拉取一次网卡mac地址,usb0 mac地址和我们的WiFi网卡mac地址不一样,不会给你释放数据
  • 批量处理:放入开机脚本
# !/bin/sh
sh /etc/udev/rules.d/80-net-setup-link.rules
while true;
do
curl -X POST -d '{"api": "get", "module": "nhx", "version": "1.0", "sid": "0000"}' http://188.168.1.1/api | jq '.result.mac' >/tmp/nhxmac
sed -i 's/"//g' /tmp/nhxmac
mac_addr=$(cat /tmp/nhxmac)
mac_orig=$(cat /etc/nhxmac)
if [ "$mac_addr" != "" ]; then
if [ "$mac_addr" != "$mac_orig" ]; then
echo "$mac_addr" >/etc/nhxmac
sh /etc/udev/rules.d/80-net-setup-link.rules
fi
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@/root/8021x-ca-cert" http://188.168.1.1/cgi-bin/nhxcgica | jq .errcode
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@/root/8021x-client-cert" http://188.168.1.1/cgi-bin/nhxcgiclient | jq .errcode
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@/root/8021x-priv-key" http://188.168.1.1/cgi-bin/nhxcgipriv | jq .errcode
/root/nhxwifi.sh /root/nhxwifi
break
fi
sleep 5
done
  • 临时测试:sh nhxusb0mac.sh
root@RK:~# sh nhxusb0mac.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 170 0 106 100 64 2765 1670 --:--:-- --:--:-- --:--:-- 2864