LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to send an http request after router reconnect to internet on openwrt? (http://www.linuxquestions.org/questions/linux-networking-3/how-to-send-an-http-request-after-router-reconnect-to-internet-on-openwrt-928886/)

loopilla 02-11-2012 08:10 PM

How to send an http request after router reconnect to internet on openwrt?
 
I'd like to be notified about the newly assigned IP when the ISP close the connection in every 24h.
I want to send an http request to an other server to store the IP from the http header.
Is there a way to simply run a command to send the http request after success reconnection(DHCP server).

I want it to add in the router using openwrt.

Thx

protube 02-12-2012 03:47 AM

Hi

Replace the echo functions with ways you'd like to be informed about an IP change (e-mail, etc.) and hit that script in a cron job.
I don't know if there is a specific function in openwrt to do this, but the script does basically the same - it's the not the most beautiful syntax, but it works. ;)

Code:

#!/bin/bash
#set -x

# Create the log file
touch /path/to/log/file
LOG=/path/to/log/file

OLD_IP=`cat $LOG`

# grep current IP address
GETIP=$(curl -s ifconfig.me)

# log current IP address
echo $GETIP > $LOG

# check if ip changed
    if [ "$OLD_IP" == "$GETIP" ]; then
        echo 'NO change of IP address for' `hostname` $y 'on ' `date`

    elif [ "$OLD_IP" != "$GETIP" ]; then 
        echo 'NEW IP address for' `hostname` 'is:' $y 'on ' `date`
    fi

exit 0

UPDATE: I'm sorry for the inconvenience. The code above now works (inspired from here, there is also the option to let the results be mailed to you)


All times are GMT -5. The time now is 12:59 PM.