LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Trying to build simple app to notify about changes in small string... Help? (https://www.linuxquestions.org/questions/programming-9/trying-to-build-simple-app-to-notify-about-changes-in-small-string-help-84843/)

Mamour 08-23-2003 08:03 AM

Trying to build simple app to notify about changes in small string... Help?
 
Hi there!

I'll give a simple explanation about my problem. I'm using ADSL as connection, and I use an external modem/router to connect. Thus, the router takes my WAN IP, and my PC gets a LAN IP which isn't of much use.

I can fetch the WAN IP manually by connecting to the router's internal HTTP server. Anyway, I've created a shell script that outputs the WAN IP into stdout in it's purest form (xxx.xxx.xxx.xxx).

Why did I do this to begin with? Well, simply put, my ISP shifts my IP every now and then, and I'd like to find out when. Thus, I'd like to build a simple application that would use extract the WAN IP every now and then, and notify me and/or log whenever changes occur.

I have close to no programming experience, so I'm basically asking if anyone here can help me out, or point me to some tutorial that I could find useful.

Thanks in advance,

david_ross 08-23-2003 08:17 AM

Take a look at this script I worte for someone else:
http://www.linuxquestions.org/questi...threadid=80190

Just run it from a crob job.

david_ross 08-23-2003 08:31 AM

Ok it turns out that it wouldn't have worked (I assumed it did since I got no reply :(). This should do it though:
Code:

#!/bin/bash

NEWIP=`lynx -dump http://checkip.dyndns.org | grep "Current IP Address" | awk {'print $4'}`
if [ ! -f ~/mylastip ]; then
echo "NOTHING" > ~/mylastip
fi
OLDIP=`cat ~/mylastip`
if [ "$NEWIP" != "$OLDIP" ]; then
echo $NEWIP > ~/mylastip
# Change the next command to a mail command etc if you want the result mailed to you
echo Your ip address has changed from $OLDIP to $NEWIP
fi


Mamour 08-23-2003 02:58 PM

Thanks a lot for the tip! I brought my own small modifications to the script, added it in KCron, and it all seems to be going well!

Code:

#!/bin/sh

function log_notify()
{
NEWIP=`lots of stuff`
if [ ! -f ~/getip.old ]; then
        echo "nothing" > ~/getip.old
fi
OLDIP=`cat ~/getip.old`
if [ "$NEWIP" != "$OLDIP" ]; then
        echo $NEWIP > ~/getip.old
        MSG="IP address has been shifted from $OLDIP to $NEWIP!"
        xmessage -center $MSG
        LOG="[`date +%Y-%m-%d` `date +%H:%M:%S`] $MSG"
        echo $LOG >>~/getip.log
fi
}

function getip()
{
xmessage -center $NEWIP
}

case $1 in
        -l|--log)
                log_notify
        ;;
        *)
                log_notify
                getip
        ;;
esac

Is there any way to build a program in KDevelop or such that could gather data from such shell scripts? Actually, I'm interested in trying to build a simple graphical front-end to my script, where I could eventually add other stuff in and such... But I have no idea where to start.

david_ross 08-23-2003 03:01 PM

Sorry that ain't really my department I tend to stick to console apps but I'm sure it is possible.

Mamour 08-23-2003 03:05 PM

Allrighty, thanks a lot anyway, at least I got the backend right!

I'll keep on searching the web for help concerning these less important matters, the geek wannabe within me wants me to. ;-)


All times are GMT -5. The time now is 03:29 PM.