SkillAgentSearch skills...

OpenWrtScripts

A set of scripts for maintaining and testing OpenWrt

Install / Use

/learn @richb-hanover/OpenWrtScripts
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

OpenWrtScripts

This is a set of scripts (sometimes also called "Openscripts") that report, configure and measure (and improve) latency in home routers. These scripts work for OpenWrt and include:

  • getstats.sh - a script to collect troubleshooting information that helps to diagnose problems in the OpenWrt distribution.

  • opkgscript.sh - a script to save the list of currently-installed packages (say, before a sysupgrade), and then restore the full set of packages after the upgrade.

  • config-openwrt.sh - a script to configure the OpenWrt router consistently after flashing factory firmware.

  • config-spare-router.sh - Configure a "spare router" to known configuration so it's easy to re-use in a new setting.

  • print-router-label.sh - Create a printable label showing LAN address and login credentials that can be taped on the side of the router.

  • betterspeedtest.sh & netperfrunner.sh - scripts that measure the performance of your router or offer load to the network for testing.

  • idlelatency.sh - a script to measure the latency of an "idle line" without any additional traffic generation from the script.

  • tunnelbroker.sh - a script to set up a IPv6 6-in-4 tunnel to TunnelBroker.net.

These scripts can be saved in the /usr/lib/OpenWrtScripts directory. The easiest way to do this is to ssh into the router and enter these commands:

opkg update
opkg install netperf git git-http
cd /usr/lib
git clone https://github.com/richb-hanover/OpenWrtScripts.git

NB: Some of these scripts have instructions for running the script from /tmp

getstats.sh

The getstats.sh script helps diagnose problems with OpenWrt. If you report a problem, it is always helpful to include the output of this script.

getstats.sh executes a built-in set of commands and writes the collected output to /tmp/openwrtstats.txt. The script also executes commands passed as arguments on the command line. It also displays a list of user-installed opkg packages - that is those not installed by default. In the example below, the output would contain results from the standard set of commands plus the two additional arguments:

Usage: sh getstats.sh "ls /usr/lib" "ls -al /etc/config"

To install and run this script: The script is self-contained, and can be placed in any directory. Read the top of the getstats.sh file for a simple procedure for using the script.

Sample output file: See a sample output file - openwrtstats.txt

opkgscript.sh

NOTE: This script is deprecated. It still works, but when upgrading to a new OpenWrt release, a far easier option is to use the Attended Sysupgrade in recent versions of OpenWrt.

The opkgscript.sh script helps to restore the current set of packages after a sysupgrade or even a clean install of either LEDE or OpenWrt. By default, the write command saves the list of installed packages in /etc/config/opkg.installed (where it will be preserved across sysupgrades), and the install command reads the file, to restore that set of packages. Cloned from Malte Forkel's original script.

Usage:

sh opkgscript.sh write use before sysupgrade to save the current set of packages

sh opkgscript.sh install use after successful sysupgrade, to restore those packages

sh opkgscript.sh help display full help information for the script

config-spare-router.sh

Configure a "spare router" to known settings so that it's easy to use in a new situation. Many of us have a pile of routers that might be passed along to friends, family, or neighbors. But they're in an unknown state, and it's a hassle to figure out the current configuration to reuse them.

This script configures an OpenWrt router to a known state. It also prints a label that can be taped to the outside of the router so the next person "to touch it" can log in easily.

When you're taking a router out of service, install the latest OpenWrt firmware, then run this script. Print the label (below) and tape it to the router. It'll be easy to start using it again. For more details, read Why a "spare router"?

print-router-label.sh

This script retrieves values from an OpenWrt router to create a label that contains the LAN address and important credentials. Tape this label to the side of the router so the next person to encounter the router (which may be you) can access it.

This process is reasonably secure - if the bad guy can read the label, they can also factory-reset the router (or steal your TV or your silverware). Here's a sample label:

======= Printed with: print-router-label.sh =======
     Device: Linksys E8450 (UBI)
    OpenWrt: OpenWrt 23.05.5 r24106-10cc5fcd00
 Connect to: http://Belkin-RT3200.local
         or: ssh root@Belkin-RT3200.local
        LAN: 192.168.253.1
       User: root
   Login PW: abcd9876
  Wifi SSID: My Wifi SSID
    Wifi PW: <no password>
 Configured: 2024-11-28
=== See github.com/richb-hanover/OpenWrtScripts ===

Label for Power Brick: Linksys E8450 (UBI)

config-openwrt.sh

The config-openwrt.sh script updates the factory settings of OpenWrt to a known-good configuration. If you frequently update your firmware, you can use this script to reconfigure the router to a consistent state. You should make a copy of this script, customize it to your needs, then use the "To run this script" procedure (below).

This script is designed to configure the settings after an initial "factory" firmware flash. There are sections below to configure many aspects of your router. All the sections are commented out. There are sections for:

  • Set up the WAN interface to connect to your provider
  • Update the software packages
  • Update the root password
  • Set the time zone
  • Enable SNMP for traffic monitoring and measurements
  • Enable mDNS/ZeroConf on the WAN interface
  • Set the SQM (Smart Queue Management) parameters

[ Note: the remaining items have not been converted to work on OpenWrt yet ]

  • Enable NetFlow export for traffic analysis
  • Change default IP addresses and subnets for interfaces
  • Change default DNS names
  • Set the radio channels
  • Set wireless SSID names
  • Set the wireless security credentials]_

To run this script

Flash the router with factory firmware. Then telnet/ssh in and execute these statements. You should do this over a wired connection because some of these changes may reset the wireless network.

ssh root@192.168.1.1
cd /tmp
cat > config.sh
[paste in the contents of this file, then hit ^D]
sh config.sh
Presto! (You should reboot the router when this completes.)

Note: If you use a secondary OpenWrt router, you can create another copy of this script, and use it to set different configuration parameters (perhaps different subnets, radio channels, SSIDs, enable mDNS, etc).

betterspeedtest.sh

The betterspeedtest.sh script emulates the web-based test performed by speedtest.net, but does it one better. [^1] While script performs a download and an upload to a server on the Internet, it simultaneously measures latency of pings to see whether the file transfers affect the responsiveness of your network.

Here's why that's important: If the data transfers do increase the latency/lag much, then other network activity, such as voice or video chat, gaming, and general network activity will also work poorly. Gamers will see this as lagging out when someone else uses the network. Skype and FaceTime will see dropouts or freezes. Latency is bad, and good routers will not allow it to happen.

[^1]: Since the script was created all three of the major speed test sites now include a latency setting. But betterspeedtest.sh still provides good numerical results. See:

The betterspeedtest.sh script measures latency during file transfers. To invoke it:

sh betterspeedtest.sh -Z passphrase [ -4 | -6 ] [ -H netperf-server ] [ -t duration ] [ -p host-to-ping ] [ -i ] [ -n simultaneous-streams ]

Options, if present, are:

  • -H | --host: DNS or Address of a netperf server (default - netperf.bufferbloat.net) Alternate servers are netperf-east (east coast US), netperf-west (California), and netperf-eu (Denmark)
  • -4 | -6: Enable ipv4 or ipv6 testing (default - ipv4)
  • -t | --time: Duration for how long each direction's test should run - (default - 60 seconds)
  • -p | --ping: Host to ping to measure latency (default - gstatic.com)
  • -i | --idle: Don't send traffic, only measure idle latency
  • -n | --number: Number of simultaneous sessions (default - 5 sessions)
  • -Z passphrase: Required to use the default netperf.bufferbloat.net server. Visit the site to get today's value.

The output shows separate (one-way) download and upload speed, along with a summary of latencies, including min, max, average, median, and 10th and 90th percentiles so you can get a sense of the distribution. The tool also displays the percent packet loss. The example below show

Related Skills

View on GitHub
GitHub Stars622
CategoryDevelopment
Updated15d ago
Forks110

Languages

Shell

Security Score

95/100

Audited on Mar 18, 2026

No findings