1

Is there a way I can send a notification to myself when the local DHCP IP changes? Can I use libnotify?

I use Xubuntu. Below is a screenshot that shows what the notification looks like, can I design it to look like that?

Screenshot of the notification design

0

1 Answer 1

2

That would require a small background script:

enter image description here

#!/usr/bin/env python3
import subprocess
import time

ip1 = [s for s in subprocess.check_output([
    "ifconfig", "-a"]).decode("utf-8").split() \
      if "addr:192" in s][0]

while True:
    time.sleep(2)
    ip2 = [s for s in subprocess.check_output([
        "ifconfig", "-a"]).decode("utf-8").split() \
          if "addr:192" in s][0]
    if ip2 != ip1:
        subprocess.Popen([
            "notify-send", "Ip address changed",
            "New address: "+ip2.replace("addr:", "")
            ])
    ip1 = ip2

How to use

  1. Copy the script into an empty file, save it as watch_ipchange.py
  2. Test-run it from a terminal:

    python3 /path/to/watch_ipchange.py
    
  3. If all works fine, add it to Startup Applications

Explanation

  • Every two seconds, the script cheks the current local ip address from ifconfig -a
  • in case of a change, it sends a notification.

Note

I tested it on Ubuntu Unity, but that should not make a difference; both use notify-osd. If, for some reason it wouldn't work however, please comment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .