ddwrt-who-is-connected

Scripts to output who all is actively connected and to programatically open and close port forwards to your DD-WRT router


Project maintained by uriel1998 Hosted on GitHub Pages — Theme by mattgraham

ddwrt-who-is-connected

There are two (main) scripts in this repository, both written for DD-WRT routers:

ddwrt-who-is-connected: A script to output who all is actively connected to your DD-WRT router. It can also be used to trigger events depending on who is connected to your home network.

portforwards.sh: A script to programatically open and close port forwards on your DD-WRT router.

Both are described in this README.

Contents

  1. About
  2. License
  3. Prerequisites
  4. ddwrt-who-is-connected.sh
  5. portforwards.sh

1. About

2. License

This project is licensed under the MIT License. For the full license, see LICENSE.

3. Prerequisites

4. ddwrt-who-is-connected

Configuration

You must configure connection_outputs.sh with the appropriate names of the computers and routers that are connected, and comment out the ones that you are not interested in. For example, if the device that is statically assigned to 192.168.1.110 is “Spouse’s Android” then ensure that you have this line:

sed -i '/192.168.1.110/ s/$/ - Spouse iPhone/' $activetemp

and proceed accordingly.

You will also want to either edit the output file (line 14) or pass it as the first commandline option.

If you want to use the output in a webpage, uncomment line 96.

If you want to use a particular SSH configuration file, see the example on line 42

Utility

Aside from a fairly easy monitoring service (you can have this redirect to a local webserver, for example), you can also then use this script to trigger other things instead of relying on portable devices.

For a simple example, you could have a cronjob that has the following:

   bob=$(grep -c "Spouse iPhone" $HOME/client_ips.txt)
   if [ "$bob" == "1" ];then
      do a command that your spouse wants when they get home
   fi

(Note that you will have to use the full path of $HOME if you’re really using a cron job…)

You can see example.sh as a fairly robust starting point, or even full featured way to use this, if you don’t mind specifying the command line variables.

Output

The output file will look like this:

   192.168.1.104 - Name of Device
   192.168.1.108 - Name of Device
   192.168.1.109 - Name of Device
   192.168.1.111 - Name of Device
   192.168.1.116 - Name of Device
   192.168.1.120 - Name of Device
   192.168.1.4 - Name of Device
   192.168.1.5 - Name of Device
   555.555.555.555 - gateway 
   ######### Offline Nodes
   * 192.168.1.102 - Name of Device
   * 192.168.1.105 - Name of Device
   * 192.168.1.107 - Name of Device

Please note that additional routers may appear in the “offline” list if you have configured them to reject PING requests.

5. portforwards

portforwards.sh is designed to be called as part of an SSH connection:

ssh -q [ROUTER IP] 'sh -s' < ./portforwards.sh [ADD|DEL] [PORT NUMBER] [PROTOCOL] [DEST IP]

If you are deleting port forwards, you only need to specify the port number; DEL commands remove ALL rules matching that port number regardless of protocol.

ssh -q [ROUTER IP] 'sh -s' < ./portforwards.sh DEL 443

If you are adding a port forward, you need to specify the protocol and destination IP address in numerical format.

ssh -q [ROUTER IP] 'sh -s' < ./portforwards.sh ADD 443 TCP 192.168.1.324 

ssh -q [ROUTER IP] 'sh -s' < ./portforwards.sh ADD 25565 BOTH 192.168.1.324 

Usage notes

Utility

As an example, here is a start.sh used to open the ports for a Minecraft server that is located on a machine with the LAN IP address of 192.168.1.324, with the router existing at 192.168.1.1, and then close the ports when the server goes down. PLEASE NOTE that this example assumes that portforwards.sh is in the same directory; replace ./portforwards.sh with the full path to the file otherwise.

#!/usr/bin/env bash

ssh -q 192.168.1.1 'sh -s' < ./portforwards.sh ADD 25565 BOTH 192.168.1.324 

java -jar -Xms2048m -Xmx2048m -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M fabric-server-launch.jar nogui

ssh -q 192.168.1.1 'sh -s' < ./portforwards.sh DEL 25565

Steven Saus injects people with radioactivity for his day job, but only to serve the forces of good.
Mostly.