海运的博客

openwrt使用dnspod api自动更新ddns

发布时间:February 12, 2019 // 分类:OpenWrt // No Comments

通过dnspod api实现动态ddns更新ip,shell脚本如下:

#!/bin/sh
token="xxxxxxxxxxxxxxxx"
domain="haiyun.me"
name="test"
if [ "$1" != "${1#*[0-9].[0-9]}" ]; then
  curl -s -d "login_token=$token&format=json&domain=$domain" "https://dnsapi.cn/Record.List" -o /tmp/dns.txt
  if grep -q '"code":"1"' /tmp/dns.txt; then
    if grep -q "\"name\":\"$name\"" /tmp/dns.txt; then
      ip=`jsonfilter -i /tmp/dns.txt -e "@.records[@.name='$name'].value"`
      echo $ip
      ip_state=$?
      id=`jsonfilter -i /tmp/dns.txt -e "@.records[@.name='$name'].id"`
      id_state=$?
      if [ $ip_state -eq 0 ] && [ $id_state -eq 0 ] && [ "$ip" != "$1" ] && [ "$id" != "" ];then
        echo "mod ip"
        if curl -s -d "login_token=$token&format=json&domain=$domain&record_id=$id&value=$1&record_type=A&record_line_id=0&sub_domain=$name" https://dnsapi.cn/Record.Modify|grep  -q '"code":"1"';then
          echo "sus"
        fi
      fi
    else
      echo "add ip"
      if curl -s -d "login_token=$token&format=json&domain=$domain&sub_domain=$name&record_type=A&record_line_id=0&value=$1" https://dnsapi.cn/Record.Create|grep  -q '"code":"1"';then
        echo "sus"
      fi
    fi
  fi
else
  logger -t ddns "invalid IP address $1"
fi

在/lib/netifd/ppp-up文件内调用上面的脚本,当pppoe网络连接成功时会执行此文件,$4变量为pppoe连接的本地IP。

/usr/bin/update-ip.sh $4 > /dev/null 2>&1 &

PHP版本:
https://www.haiyun.me/archives/1186.html

ImageBuilder制作k2p潘多拉/PandoraBox固件

发布时间:November 2, 2018 // 分类:K2P // 8 Comments

基于ubuntu 18.04,安装依赖:

apt install build-essential libncurses5-dev zlib1g-dev gawk git  libssl-dev wget unzip python ocaml-nox help2man texinfo yui-compressor

下载最新版本18.10的ImageBuilder:

https://downloads.pangubox.com/pandorabox/18.10/targets/ralink/mt7621/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64.tar.xz
tar Jxf PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64.tar.xz
cd PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64

查看可编译的固件型号及其包含的软件包:

make info

制作固件:

#info显示的所有机型固件
make image
#仅制作k2p固件
make image PROFILE="k2p"
#安装额外的软件包,自编译软件先把软件放到packages/目录下
make image PROFILE="k2p" PACKAGES="wget"
#添加files目录内文件到固件内,如files/etc/config/network网络配置文件
make image PROFILE="k2p" FILES="files"
#查看更多选项
make help

默认的软件包在以下两个文件内:

include/target.mk
.profiles.mk 

开始使用默认配置制作k2p固件:

make image PROFILE="k2p"

遇到以下错误:

 regexp could be something like 'pkgname*' '*file*' or similar
 e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'
Makefile:140: recipe for target 'package_install' failed
make[2]: *** [package_install] Error 1
make[2]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:110: recipe for target '_call_image' failed
make[1]: *** [_call_image] Error 2
make[1]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:196: recipe for target 'image' failed
make: *** [image] Error 2

因为在Makerfile 144行要预先安装kernel文件,而package没kernel软件包,下载kernel:

wget https://downloads.pangubox.com/pandorabox/18.10/targets/ralink/mt7621/packages/kernel_3.14.79-1_mipsel_1004kc_dsp.ipk -P packages/

再次执行又出现错误:

Collected errors:
 * opkg_install_cmd: Cannot install package dosfsck.
 * opkg_install_cmd: Cannot install package fkmod-leds-gpio.
 * opkg_install_cmd: Cannot install package kmod-ipt-nathelper.
 * opkg_install_cmd: Cannot install package mkdosfs.
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for ralink-utils:
 *      kmod-ipt-nathelper-extra * 
Makefile:140: recipe for target 'package_install' failed
make[2]: *** [package_install] Error 255
make[2]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:110: recipe for target '_call_image' failed
make[1]: *** [_call_image] Error 2
make[1]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:196: recipe for target 'image' failed
make: *** [image] Error 2

因为新版的openwrt将kmod-ipt-nathelper-extra 更改为kmod-nf-nathelper-extra,而潘多拉的源package没修改依赖,使用以下脚本在制作时更新源后修改软件依赖项kmod-ipt-nathelper-extra为kmod-nf-nathelper-extra:

#!/bin/bash
for file in `ls dl/18.10*`;do 
        echo $file;
        mv $file $file.gz
        gunzip $file.gz
        sed -i 's/kmod-ipt-nathelper-extra/kmod-nf-nathelper-extra/g' $file
        gzip -9 $file
        mv $file.gz $file
done
sed -i 's/kmod-ipt-nathelper/kmod-nf-nathelper/g' include/target.mk 

将以上保存为fix.sh到image build目录加可执行权限,并修改Makefile文件在122行$(MAKE) package_install前插入:

$(TOPDIR)/fix.sh

再次执行又遇到以下错误:

Collected errors:
 * opkg_install_cmd: Cannot install package dosfsck.
 * opkg_install_cmd: Cannot install package fkmod-leds-gpio.
 * opkg_install_cmd: Cannot install package mkdosfs.

因为上面这3个软件有的改名,有的名字写错,修复下:

sed -i 's/fkmod-leds-gpio/kmod-leds-gpio/g' .profiles.mk
sed -i 's/mkdosfs dosfsck/dosfstools/g' .profiles.mk

再次执行终于制作完成k2p固件,将制作的固件scp到路由/tmp/目录开始刷机:

scp bin/targets/ralink/mt7621/PandoraBox-ralink-mt7621-k2p-2018-10-26-git-85c67caa2-squashfs-sysupgrade.bin 192.168.168.1:/tmp/

k2p路由内使用sysupgrade命令刷机

sysupgrade -n -v /tmp/PandoraBox-ralink-mt7621-k2p-2018-10-26-git-85c67caa2-squashfs-sysupgrade.bin

Openwrt下转守护进程runit使用

发布时间:February 11, 2015 // 分类:OpenWrt // No Comments

类似于s6,不过runit在openwrt busybox中自带,需编译openwrt固件时选择。
runsvdir用以扫描指定目录子目录下run脚本并使用runsv启动为守护进程:

runsvdir -P /etc/config/service/

一个openconnect启动脚本示例,注意启动的程序一定要以非守护进程启动且以exec命令执行:

cat /etc/config/service/openconnect/run 
exec 2>&1
exec openconnect -c user-cert.pem -k user-key.pem -s /etc/config/vpnc --no-cert-check www.haiyun.me

如果run目录存在finish脚本,run执行的程序退出后runsv会执行finish并传递程序退出code给finish参数1,然后再重新执行run启动程序,我们可以使用finish判断当网络不通时程序退出状态,避免程序持续启动退出导致死循环:

#!/bin/sh
if [ $1 -eq 255 ]
then
  sleep 5
else
  exit
fi

控制启动的程序,更多见http://smarden.org/runit/sv.8.html

sv status /etc/config/service/openconnect/
sv stop /etc/config/service/openconnect/
sv start /etc/config/service/openconnect/
sv restart /etc/config/service/openconnect/

也可以用runit管理ssh动态隧道转发实现类似于autossh的功能,ssh连接时使用超时控制,超时后ssh关闭runsv会自动重启ssh。
更多示例:
http://smarden.org/runit/runscripts.html

此内容被密码保护

发布时间:February 11, 2015 // 分类:OpenWrt // No Comments

请输入密码访问

Openwrt无线管理工具/命令

发布时间:February 9, 2015 // 分类:OpenWrt // No Comments

查看连接Openwrt路由的无线客户端:

iwinfo wlan0 assoclist
iw dev wlan0 station dump

查看分配的DHCP客户端IP:

 cat /tmp/dhcp.leases 

扫描无线路由器/AP:

iwinfo wlan0 scan

查看Openwrt路由无线信息:

iwinfo wlan0 info
wlan0     ESSID: "OpenWrt"
          Access Point: 00:1F:A3:65:55:8E
          Mode: Master  Channel: 5 (2.432 GHz)
          Tx-Power: 20 dBm  Link Quality: 30/70
          Signal: -80 dBm  Noise: unknown
          Bit Rate: 32.5 MBit/s
          Encryption: WPA2 PSK (CCMP)
          Type: nl80211  HW Mode(s): 802.11bg
          Hardware: unknown [Generic MAC80211]
          TX power offset: unknown
          Frequency offset: unknown
          Supports VAPs: no  PHY name: phy0

重启无线:

wifi down && sleep 5 && wifi

一个bash脚本,输出当前无线客户端IP/MAC/名称/速率:

#!/bin/bash
echo -e "# IP address\tname\tMAC address\ttx bit\trx bit"
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
  maclist=(`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`)
  txlist=(`iw dev wlan0 station dump|grep 'tx bitrate'|awk '{print $3$4}'`)
  rxlist=(`iw dev wlan0 station dump|grep 'rx bitrate'|awk '{print $3$4}'`)
  len=${#maclist[@]}
  for ((i=0;i<$len;i++))
  do
    mac=${maclist[$i]}
    tx=${txlist[$i]}
    rx=${rxlist[$i]}
    ip="UNKN"
    host=""
    ip=`cat /tmp/dhcp.leases | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
    host=`cat /tmp/dhcp.leases | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
    echo -e "$ip\t$host\t$mac\t$tx\t$rx"|awk '{printf "%-15s %-25s %-15s %-10s %-10s\n",$1,$2,$3,$4,$5}'
  done
done

http://wiki.openwrt.org/doc/faq/faq.wireless
http://wiki.openwrt.org/doc/howto/wireless.utilities

分类
最新文章
最近回复
  • 海运: 正常情况下编译整个内核执行make menuconfig后就不会出现此提示,当单独编译单个模块...
  • oijq: 就是用的armbian的配置文件哈,按你的教程做的,在执行make LOCALVERSION=...
  • 海运: 使用armbian的配置文件,其它添加或修改自己懂的部分,不懂的就不要碰了。
  • oijq: 编译时这些选项全部选Y吗?Actions Semi Platforms (ARCH_ACTIO...
  • 海运: n1编译bbr内核模块参考这个:https://www.haiyun.me/archives/...
  • jiqz: make M=net/ipv4/ CONFIG_TCP_CONG_BBR=m modules编...
  • ruralhunter: 哦,文档里应该是对的,是.config
  • ruralhunter: cp /mnt/boot/config-4.18.7-aml-s9xxx .config这里应...
  • 海运: 你是编译不成功呢?还是编译后不能运行呢?还是运行后不能访问web界面呢?
  • 白墨: 可能不清楚就是编译安装后启动后访问不了web界面