Results 1 to 9 of 9

Thread: Detecting external IP address change

  1. #1
    Join Date
    May 2007
    Beans
    230
    Distro
    Ubuntu

    Detecting external IP address change

    Hi all

    Have a client with a dynamic IP address.

    Every 5 minutes a script is executed that checks for a change in the external IP address through a CRON job
    Code:
    */5 * * * * /var/data/bin/zoneedit.sh
    If the address has changed, then www.zoneedit.com is updated with the new IP address.

    Code:
    #!/bin/bash
    
    ipfile='/var/data/bin/ipaddress'
    
    [[ -f "$ipfile" ]] && ipold="$(< "$ipfile" )"
    ipnew="$( wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //;s/<.*$//' )"
    
    if [[ "$ipold" != "$ipnew" ]]; then......
    
    fi
    This works but there maybe a 5 minute delay, at maximum, before the update takes place.

    Are there any alternative ways to detect an external IP address change and thus cause the second part of the script to run?

    TIA

  2. #2
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Detecting external IP address change

    Hi

    Is the box directly connected to the internet or behind a router with port forwarding ?

    You're running ubuntu and dhclient ?

    Kind regards

  3. #3
    Join Date
    May 2007
    Beans
    230
    Distro
    Ubuntu

    Re: Detecting external IP address change

    matt_symes

    Thanks for your reply.

    Behind a router with port forwarding

    Ubuntu yes,
    dhclient no.

  4. #4
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    5,169
    Distro
    Kubuntu

    Re: Detecting external IP address change

    you can mod the script i made:
    http://pastebin.com/16jKus3r
    here is a script a person made that uses multiple ip checkers
    https://github.com/tknorris/duckdns/...kdns_upd_ip.sh
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  5. #5
    Join Date
    Nov 2008
    Location
    S.H.I.E.L.D. 6-1-6
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Detecting external IP address change

    What model of router do you have?

    ddclient can access the status page of *some* routers and get the ip from there.
    Don't waste your energy trying to change opinions ... Do your thing, and don't care if they like it.

  6. #6
    Join Date
    May 2007
    Beans
    230
    Distro
    Ubuntu

    Re: Detecting external IP address change

    pqwoerituytrueiwoq

    Thanks for your reply - will take a look

    sandyd

    Thanks for your reply - Netgear DG834G

  7. #7
    Join Date
    Nov 2008
    Location
    S.H.I.E.L.D. 6-1-6
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Detecting external IP address change

    Quote Originally Posted by ChrisRChamberlain View Post
    pqwoerituytrueiwoq

    Thanks for your reply - will take a look

    sandyd

    Thanks for your reply - Netgear DG834G
    Yes, that router should work fine.

    You will have to configure ddclient to read the ip from the router status page - here is a page on how to do it (will need to scroll down a bit)
    Don't waste your energy trying to change opinions ... Do your thing, and don't care if they like it.

  8. #8
    Join Date
    May 2007
    Beans
    230
    Distro
    Ubuntu

    Re: Detecting external IP address change

    sandyd

    Many thanks - will go figure it out

  9. #9
    Join Date
    May 2007
    Beans
    230
    Distro
    Ubuntu

    Re: Detecting external IP address change

    sandyd

    Thanks for resolving the question
    Are there any alternative ways to detect an external IP address change...
    In this instance and with this router, it provides a solution.

    However in the long term it may not as the router may change and not be supported.

    Am going to rewrite the first part of the script and error trap variables with a length of 0, etc, which will prevent the second half being executed.

    Also going to add an alternative to
    Code:
    ipnew="$( wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //;s/<.*$//' )"
    using
    Code:
    ipnew="$( curl ident.me )"
    which should also prevent the second half being executed if no IP address is returned.

    This also means the time interval can be reduced to three minutes so either external resource is 'polled' only every six minutes.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •