LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-23-2003, 09:03 AM   #1
Mamour
LQ Newbie
 
Registered: Aug 2003
Location: Brussels, Belgium
Distribution: Debian Sid
Posts: 9

Rep: Reputation: 0
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,
 
Old 08-23-2003, 09:17 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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.
 
Old 08-23-2003, 09:31 AM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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
 
Old 08-23-2003, 03:58 PM   #4
Mamour
LQ Newbie
 
Registered: Aug 2003
Location: Brussels, Belgium
Distribution: Debian Sid
Posts: 9

Original Poster
Rep: Reputation: 0
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.
 
Old 08-23-2003, 04:01 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Sorry that ain't really my department I tend to stick to console apps but I'm sure it is possible.
 
Old 08-23-2003, 04:05 PM   #6
Mamour
LQ Newbie
 
Registered: Aug 2003
Location: Brussels, Belgium
Distribution: Debian Sid
Posts: 9

Original Poster
Rep: Reputation: 0
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. ;-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to build small linux guosheng Linux - Newbie 2 04-28-2005 07:33 PM
any small linux app you would like to see feetyouwell Linux - General 9 01-28-2005 11:05 PM
Kylix3 (kde 3.2) app font is so small I cant see! Dark Carnival Linux - Software 2 08-25-2004 06:43 AM
simple C string question mvendramini Programming 9 09-30-2003 08:05 PM
Where can I get a small linux app? gqchynaboy Linux - General 2 07-23-2003 10:15 PM


All times are GMT -5. The time now is 02:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration