https://github.com/takuya/openwrt-uci-dhcp-sort
sort openwrt dhcp hosts
https://github.com/takuya/openwrt-uci-dhcp-sort
Last synced: about 1 year ago
JSON representation
sort openwrt dhcp hosts
- Host: GitHub
- URL: https://github.com/takuya/openwrt-uci-dhcp-sort
- Owner: takuya
- License: gpl-3.0
- Created: 2023-02-13T15:38:05.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-06T14:27:44.000Z (over 2 years ago)
- Last Synced: 2025-02-09T01:14:04.926Z (over 1 year ago)
- Language: Lua
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openwrt / sort uci static DHCP v4 lease.
Sort openwrt dhcp-static-lease-hosts.
No v6 available.
if your uci have a v6 static lease dhcp , this script will disrupt dhcp.host.
# how to use
Copy file into OpenWrt. Run by Lua
### command
ssh into wrt do this
```
lua uci-sort-dhcp-hosts.lua
```
# what does this script do.
- Backup dhcp.@host to /tmp.
- Get list `uci show dhcp` and eval dhcp.@host to lua.
- Sort dhcp.hosts by ip addr.
- Remove all exists by `uci del dhcp.host..`.
- Add sorted by `uci add dhcp.host `.
- And commit by executing `uci commit dhcp`.
# how to sort ip address
Sort ip as interger by casting ipv4 to Int.
# uci dhcp sample
Modifying uci dhcp.hosts samples.
```sh
### get current dhcp hosts
uci show dhcp
### revert changes
uci revert dhcp
### commit dhcp
uci commit dhcp
### remove all exist dhcp.hosts
while uci del dhcp.@host[-1] ; do : ; done;
### add a new dhcp.host
uci add dhcp host
uci set dhcp.@host[-1].dns='1'
uci set dhcp.@host[-1].mac='dc:a6:32:dd:23:c6'
uci set dhcp.@host[-1].ip='192.168.1.22'
uci set dhcp.@host[-1].leasetime='86400'
uci set dhcp.@host[-1].name='raspi-ubuntu'
```
# uci show dhcp via ssh
if you are using ruby or python or JavaScript(node), you can rewrie via ssh.
### sample
In your favorite language. you can do like this.
JS/python
```
ssh root@192.168.1.1 'uci show dhcp' \
| \grep dhcp.@host | sed -E 's/@//' | sed -E 's/=host/={}/' >> dhcp.js
```
ruby
```
ssh root@192.168.1.1 'uci show dhcp' \
| \grep dhcp.@host | sed -E 's/@//' | sed -E 's/=host/=OpenStruct.new/' >> dhcp.rb
```