Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-08, 09:24 PM
james james is offline
Guru
 
Join Date: Oct 2007
Location: Tempe, AZ
Posts: 276
DNS-O-Matic
https://www.dnsomatic.com/dnsomatic will update most popular dynamic dns servives. I named the script dns-o-matic and put it in usr/bin. It is called via Cron every night 1 minute to midnight:
59 23 * * * /usr/bin/dns-o-matic>/dev/null 2>&1

Code:
#/bin/bash
USERNAME="dnsomaticuser"
PASSWORD="dnsomaticpass"
ip=$(curl -s www.wieistmeineip.de | awk '(/[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]/) {print}' | awk 'gsub(/[>||<]/," ")' | awk '{print $3}')
echo $ip
result=$(curl -s https://${USERNAME}:${PASSWORD}@updates.dnsomatic.com/nic/update?hostname=all.dnsomatic.com&myip=$ip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG)
echo $result
__________________
James
Rhino Equipment
https://support.rhinoequipment.com
Reply With Quote
  #2  
Old 04-25-08, 10:14 AM
TomS TomS is offline
Senior Member
 
Join Date: Oct 2007
Posts: 175
Just another way to just get the IP address
I tested your script and it works well - Thanks very much!

I wanted to see if there was another source to get the IP Address and went to "Whatismyip.com". In the page it has a link to:
http://www.whatismyip.com/automation/n09230945.asp
This just gives you your IP Address only so no parsing is needed.

I also added a logging feature so you can test for your IP easily in a script.

Here is what it looks like so far: (I always add .sh to shell scripts)

# dns-o-matic.sh DNS-O-MATIC by James at Rhino

# "crontab -e" and then insert the appropriate line.
# Insert in crontab to run every night 1 minute to midnight:
# 59 23 * * * /usr/bin/dns-o-matic.sh >/dev/null 2>&1
# Remember to place the program in /usr/bin
# Make it executable "chmod 755 /usr/bin/dns-o-matic.sh"

USERNAME="dnsomaticuser"
PASSWORD="dnsomaticpass"

# Bring up the webpage that shows your IP address
# Select out your IP Address
ip=$(curl -s http://www.whatismyip.com/automation/n09230945.asp)
# Or ip=$(curl -s http://myip.dnsomatic.com)

# Print your IP Address
echo $ip

# Update dns-o-matic
# Don't forget to create an account at dnsomatic.com and select the appropriate service e.g. dyndns
# Use the same line as in the original script above:
result=$(curl -s https://${USERNAME}:${PASSWORD}@upda...G&backmx=NOCHG)

# Log the IP Address (dot filename will not be deleted on reboot)
echo -e "`date`:$ip" >> /tmp/.DNSOMATIC-LOG
chmod 666 /tmp/.DNSOMATIC-LOG

Thanks TomS

Last edited by TomS : 04-25-08 at 10:38 AM.
Reply With Quote
  #3  
Old 04-26-08, 01:33 AM
james james is offline
Guru
 
Join Date: Oct 2007
Location: Tempe, AZ
Posts: 276
I am going to work this in to a freepbx module that allows you to set the username, password, and schedule the cron from the gui... well that's the goal. So I have converted this to php.....

PHP Code:

#!/usr/bin/php -q 
<?php
/*DNSOMATIC ala php
By James Finstrom
"crontab -e" and then insert the appropriate line.
Insert in crontab to run every night 1 minute to midnight:
59 23 * * * /usr/bin/dnsomatic.php username password >/dev/null 2>&1
Remember to place the program in /usr/bin
Make it executable "chmod 755 /usr/bin/dnsomatic.php"
*/
//logger
function ip_log($data){
$fp fopen('/tmp/.DNSOMATIC-LOG''a');
$stamp date(r);
fwrite($fp,"$stamp $data \n");
fclose($fp);
}
//get ip
function get_ip() {
$handle fopen("http://www.whatismyip.com/automation/n09230945.asp",r);
$ip fread($handle256);
fclose($handle);
ip_log("Received $ip");
return 
$ip;
}
//updates ip
function update_ip($user$pass$ip){
$handle fopen("https://$user:$pass@updates.dnsomatic.com/nic/update?hostname=all.dnsomatic.com&myip=$ip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG",r);
$result fread($handle256);
fclose($handle);
return 
$result;
}
//calls the functions above
$result update_ip($argv[1], $argv[2], get_ip());
$result explode(" "$result);
// log it
$message "Update IP to $result[1] was $result[0]";
ip_log($message);

echo 
$message;


?>
__________________
James
Rhino Equipment
https://support.rhinoequipment.com

Last edited by james : 04-26-08 at 01:35 AM.
Reply With Quote
  #4  
Old 04-27-08, 10:03 AM
TomS TomS is offline
Senior Member
 
Join Date: Oct 2007
Posts: 175
Great Idea!
Great Idea!
I am a shell programmer - the perl looks great and very straight forward.
thanks
Tom
Reply With Quote
  #5  
Old 05-03-08, 05:59 AM
hjm hjm is offline
Junior Member
 
Join Date: Dec 2007
Location: Purmerend NL
Posts: 18
Originally Posted by TomS View Post
I tested your script and it works well - Thanks very much!
I've tested this script and for me it did not work. Not being a programmer, i've done some cutting and pasting and combined your script with that of Nerd Vittles. I have accomplished two things now. First my children surf safe because OpenDNS knows my IP and secondly externIP gets updated.
This is what i made of it:

#!/bin/bash
# dns-o-matic.sh DNS-O-MATIC by James at Rhino, TomS, Ward Mundy & hjm

# "crontab -e" and then insert the appropriate line.
# Insert in crontab to run every 5 minutes:
# */5 * * * * /usr/bin/dns-o-matic.sh >/dev/null 2>&1
# Remember to place the program in /usr/bin
# Make it executable "chmod 755 /usr/bin/dns-o-matic.sh"

USERNAME="dns_o-matic_username"
PASSWORD="dns_o-matic_password"
localnet="192.168.1.0"

# Bring up the webpage that shows your IP address
# Select out your IP Address
ip=$(curl -s http://www.whatismyip.com/automation/n09230945.asp)
# Or ip=$(curl -s http://myip.dnsomatic.com)

# Print your IP Address
echo $ip

# Update dns-o-matic
# Don't forget to create an account at dnsomatic.com and select the appropriate service e.g. dyndns
# Use the same line as in the original script above:

if [ -e /tmp/$ip ] ; then
echo No IP Update Required ;
# echo -e "`date`:$ip" No update >> /tmp/.DNSOMATIC-LOG
else
echo IP Update Required ;
# Log the IP Address (dot filename will not be deleted on reboot)

echo -e "`date`:$ip" >> /tmp/.DNSOMATIC-LOG
chmod 666 /tmp/.DNSOMATIC-LOG

# Write to DNS-O-Matic
result=$(curl -s https://${USERNAME}:${PASSWORD}@updates.dnsomatic.com/nic/update?hostname=all.dnsomatic.com&myip=$ip&wildcar d=NOCHG&mx=NOCHG&backmx=NOCHG)
touch /tmp/$ip ;
echo "nat=yes" > /etc/asterisk/sip_nat.conf
echo "externip=$ip" >> /etc/asterisk/sip_nat.conf
echo "localnet=$localnet/255.255.255.0" >> /etc/asterisk/sip_nat.conf
asterisk -rx "dialplan reload" ;
fi

Thanks all

Last edited by hjm : 05-04-08 at 01:02 AM. Reason: changed sip_custom to sip_nat
Reply With Quote
  #6  
Old 05-03-08, 09:21 PM
james james is offline
Guru
 
Join Date: Oct 2007
Location: Tempe, AZ
Posts: 276
I had thought about the second half of the script especially if i make this a freepbx module... I am thinking it may be more appropriate to add a sip_ext.conf that can be added as an include. If someone is use to using sip_custom for certain tasks it would be bad kerma to over write it
__________________
James
Rhino Equipment
https://support.rhinoequipment.com
Reply With Quote
  #7  
Old 05-04-08, 12:53 AM
hjm hjm is offline
Junior Member
 
Join Date: Dec 2007
Location: Purmerend NL
Posts: 18
Originally Posted by james View Post
I had thought about the second half of the script especially if i make this a freepbx module... I am thinking it may be more appropriate to add a sip_ext.conf that can be added as an include. If someone is use to using sip_custom for certain tasks it would be bad kerma to over write it
You are right. Just after i posted this i made a little change and let it write to sip_nat.conf.
I will update my earlier post.
Reply With Quote
  #8  
Old 02-06-09, 12:40 PM
brunski brunski is offline
Junior Member
 
Join Date: Oct 2007
Posts: 29
just adding some email notifications

#!/bin/bash
# dns-o-matic.sh DNS-O-MATIC by James at Rhino, TomS, Ward Mundy & hjm, brunski

# "crontab -e" and then insert the appropriate line.
# Insert in crontab to run every 5 minutes:
# */5 * * * * /usr/bin/dns-o-matic.sh >/dev/null 2>&1
# Remember to place the program in /usr/bin
# Make it executable "chmod 755 /usr/bin/dns-o-matic.sh"

USERNAME="dns_o-matic_username"
PASSWORD="dns_o-matic_password"
localnet="192.168.1.0"
EMAIL=your-email-address


# Bring up the webpage that shows your IP address
# Select out your IP Address
ip=$(curl -s http://www.whatismyip.com/automation/n09230945.asp)
# Or ip=$(curl -s http://myip.dnsomatic.com)

# Print your IP Address
echo $ip

# Update dns-o-matic
# Don't forget to create an account at dnsomatic.com and select the appropriate service e.g. dyndns
# Use the same line as in the original script above:

if [ -e /tmp/$ip ] ; then
echo No IP Update Required ;
# echo -e "`date`:$ip" No update >> /tmp/.DNSOMATIC-LOG
else
echo IP Update Required ;
# Log the IP Address (dot filename will not be deleted on reboot)

echo -e "`date`:$ip" >> /tmp/.DNSOMATIC-LOG
chmod 666 /tmp/.DNSOMATIC-LOG

# Write to DNS-O-Matic and send an email

echo 'IP address for' `hostname -f` 'is:' $ip 'on ' `date` | mail -s 'New IP' $EMAIL

result=$(curl -s https://${USERNAME}:${PASSWORD}@updates.dnsomatic.com/nic/update?hostname=all.dnsomatic.com&myip=$ip&wildcar d=NOCHG&mx=NOCHG&backmx=NOCHG)
touch /tmp/$ip ;
echo "nat=yes" > /etc/asterisk/sip_nat.conf
echo "externip=$ip" >> /etc/asterisk/sip_nat.conf
echo "localnet=$localnet/255.255.255.0" >> /etc/asterisk/sip_nat.conf
asterisk -rx "dialplan reload" ;
fi

#send email notifying of job execution
echo 'Cron Job: dns-o-matic executed for' `hostname` 'on ' `date` 'ip: ' $ip | mail -s 'dns-o-matic cron job' $EMAIL
Reply With Quote
  #9  
Old 02-07-09, 06:03 AM
dstroot dstroot is offline
Member
 
Join Date: Dec 2007
Posts: 30
Brilliant!
Reply With Quote
  #10  
Old 02-07-09, 12:56 PM
brunski brunski is offline
Junior Member
 
Join Date: Oct 2007
Posts: 29
obviously the email thing works nicely when you have your cron job running once a day: i.e,

59 23 * * * /usr/bin/dns-o-matic.sh >/dev/null 2>&1

otherwise it just gets too anonying
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:01 PM.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007-2008, Ward Mundy & Associates