I have two custom solutions you might be able to utilize. One uses Wifi SSID only, the other uses MAC address determination.
Both versions have a prerequisite of you having a working ddclient
configuration for OpenDNS.
Step 1 for both: Disable ddclient
automatic executions.
I know the guide you used to set this up had you set it up as a daemon, but we are going to disable the automated ddclient
update processes.
Edit /etc/default/ddclient
. We're going to disable the daemon mode to start with, and disable dhclient
and ipup
integrations. That should make it look similar to this:
# Configuration for ddclient scripts
# generated from debconf on Tue Jun 26 12:45:45 EDT 2018
#
# /etc/default/ddclient
# Set to "true" if ddclient should be run every time DHCP client ('dhclient'
# from package isc-dhcp-client) updates the systems IP address.
run_dhclient="false"
# Set to "true" if ddclient should be run every time a new ppp connection is
# established. This might be useful, if you are using dial-on-demand.
run_ipup="false"
# Set to "true" if ddclient should run in daemon mode
# If this is changed to true, run_ipup and run_dhclient must be set to false.
run_daemon="false"
# Set the time interval between the updates of the dynamic DNS name in seconds.
# This option only takes effect if the ddclient runs in daemon mode.
daemon_interval="300"
Now, disable the ddclient
service so it will not autorun. I only have the 16.04 and later syntax to disable the service, but there are other threads on "How to disable services".
sudo systemctl disable ddclient
After this is done, you can use either of the two options below and their instructions to set up customized automatic processes.
Step 2: Decide which approach you want to use: Wifi-only SSID detection, or MAC address detection. Depending on which solution you wish to go with, follow the specific section below.
Wifi Only: SSID Detection
This is the python code itself for an SSID-based detection. Put the proper Wifi SSID in for the value stored in WIFI_NETWORK_NAME
.
#!/usr/bin/python3
import shlex
import subprocess as sp
# Replace 'FillMeIn' in this line with the actual network name.
WIFI_NETWORK_NAME = "FillMeIn"
proc = sp.getoutput(shlex.split('iwconfig'))
if WIFI_NETWORK_NAME in proc:
sp.call(shlex.split('ddclient -file /etc/ddclient.conf'))
Store this code in /opt/py-selective-ddclient.py
. You may have to store this in your home directory and then copy it into /opt/
with sudo
.
Wifi and Ethernet: MAC Address Detection
This is the Python code for this solution; update the value for MAC_ADDRESS_ROUTER
accordingly:
#!/usr/bin/python3
import shlex
import subprocess as sp
# Replace the fake MAC address below with the MAC address of your router.
# Make sure to use **uppercase letters** if you have letters present.
MAC_ADDRESS_ROUTER = "01:23:45:67:89:AB"
if MAC_ADDRESS_ROUTER in sp.getoutput(shlex.split('iwgetid -ra')).upper():
sp.call(shlex.split('ddclient -file /etc/ddclient.conf'))
Store this code in /opt/py-selective-ddclient.py
. You may have to store this in your home directory and then copy it into /opt/
with sudo
.
Step 3: Automate the Python code calls.
Now, we have to automate running ddclient
, or more specifically automate the Python script. The default ddclient
settings have a 300 second (5 minute) delay between update checks.
First we need to make the Python script executable.
sudo chmod +x /opt/py-selective-ddclient.py
Then, start by making a file in /etc/cron.d/
with the following contents. Note that you will need to use sudo
to create the file.
*/5 * * * * root /opt/py-selective-ddclient.py
This executes the ddclient
manually, every 5 minutes. You can change the */5
part to make it execute at different intervals, but I am emulating ddclient
's setup here.
Now, every 5 minutes ddclient
will be called using our 'wrapper' script which does the selective determination.
Best Answer
I think what you're looking for is:
sudo ddclient -query
That command will spit out the local IP addresses of all the interfaces on the machine (eg: lo, eth0, wlan0) followed by the dynamic public IP addresses current set for with dyndns.com.
Peace.