This is a discussion on Automatic IP change notifier within the Shell scripting forums, part of the Development/Scripting category; Hello everyone, First of all thank you for reading this post! Ok, here it goes: What do I wanna create? ...
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
|||
|
Hello everyone,
First of all thank you for reading this post! Ok, here it goes: What do I wanna create? Answer: I want to create a bash script that checks my IP, and if there has been a change, send me an email, sms or automatically post the IP in a website. Why should I? There are scripts such as no-ip.org, etc.. Answer: Even though I am using those as a guide, the truth is I want to make it better! Any help would be highly appreciated. What have you done so far? Answer: So far, this is all I got but it does not work! #!/bin/bash # The ultimate solution to my DNS problem LOOKUP=`host subdomain.mydomain.com | awk '{print $4}'` MYIP=`curl -s IP Chicken - What is my IP? Find Your IP Address! | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}'` # Do the work if [ "$LOOKUP" = "$MYIP" ]; then echo "No change in your IP." else echo "The IP address has changed. " #Either send me an: email, sms or post it in a site. #mail -s "Here is the IP ... " username@mydomain.com #echo `lynx -auth=${USERNAME}:${PASSWORD} -source "http://subdomain.mydomain.com"` fi What seems to be the problem is that the host command has some extra information that does not allow it to make a good comparison, so I always get the message that it has change. Please help me out, I'm a quick learner! ~Saya ![]() |
| Sponsored Links | ||
|
|
|
||||
|
I have an adsl account that works through pppoe, this is my script:
Code:
#!/bin/bash
#set -x
IFACE=ppp0
EMAIL=you@domain
LOG=/your/log/path/ip
OLD_IP=`cat $LOG`
# get current ip on IFACE
x=`/sbin/ifconfig $IFACE`
y=${x#*inet addr:}
y=${y%% *}
# log current ip
echo $y > $LOG
# check if ip changed
# if we have disconnected for a long time
if [[ -z "$OLD_IP" ]] && [[ "$y" ]]; then
# report new ip
echo 'New IP address for' `hostname` 'is:' $y 'on ' `date` | mail -s 'New IP' $EMAIL
# if ip changed since last check
elif [[ "$OLD_IP" ]] && [[ "$y" ]]; then
if [ "$y" != "$OLD_IP" ]; then
# report new ip
echo 'New IP address for' `hostname` 'is:' $y 'on ' `date` | mail -s 'New IP' $EMAIL
fi
fi
exit 0
|
|
|||
|
Thanks but I do not know if that script would work...
I am connected via router to the internet, it is not straight through. Here is a copy of my ifconfig: sayayinx@sayayinx:~$ ifconfig eth0 Link encap:Ethernet HWaddr 00:E0:18:5A:G1:F0 inet addr:192.168.1.101 Bcast:255.255.255.255 Mask:255.255.255.0 inet6 addr: fe80::3e0:18ff:fe5a:c1f0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:31898184 errors:0 dropped:0 overruns:0 frame:0 TX packets:30138060 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12692099512 (12.5 GiB) TX bytes:12820138230 (12.6 GiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:10926 errors:0 dropped:0 overruns:0 frame:0 TX packets:10926 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1583104 (1.5 MiB) TX bytes:1583104 (1.5 MiB) Would it work? ![]() |
|
||||
|
Quote:
You should change the "get current ip on IFACE" section. you can use some "what is my ip" web sites and grep your ip in html page, or if you have and site, web host available, write a simple php script to give JUST the visitor ip. sample php code that should work: PHP Code:
|
|
|||
|
I will use my line then:
MYIP=`curl -s IP Chicken - What is my IP? Find Your IP Address! | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}'` I know it works. But I have another question: LOG=/your/log/path/ip <= where is that folder? can i make one up? OLD_IP=`cat $LOG` <= again, is that a folder? a file? Thanks for the quick reply |
|
||||
|
please wrap code with code tag! ([ code ] [ /code ] without space in bracket
Quote:
Code:
curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq
Quote:
i have a 'scrpts' folder in my home director. and save log file with a 'log_' prefix with script name there. ex: script: /home/ali/scripts/ip_change log file: /home/ali/scripts/log_ip_change i have assigned the log file path to LOG variable in script, the in used 'LOG' variable as parameter to 'cat' command to read file content and assigned the result to 'OLD_IP' variable. you just need to define 'LOG' variable. the LOG variable points to a file. |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Automatic Mount of Windows Share | bayvista | Networking, Firewalls and Security | 0 | 02-21-2008 11:07 AM |
| Automatic startup service | gthian | Shell scripting | 0 | 06-24-2007 08:21 AM |
| Shell script for automatic conversion of files in tar files | kasimani | Shell scripting | 2 | 02-08-2007 03:45 PM |
| Automatic Sendmail | Kobi | Solaris/OpenSolaris | 2 | 01-25-2007 12:04 PM |
| How to Change Password | puppen | Linux software | 6 | 06-06-2006 01:56 PM |