The FreeBSD Diary |
![]() |
(TM) | I remember |
|
Dynamic DNS - the scripts
|
|
These are the script files for Dynamic DNS. You will need to modify the items in
bold. If you click on the <headers>, you can get the raw text instead of html. <dns_fetch.sh> #!/bin/sh
#HTTP_AUTH="basic:*"
export HTTP_AUTH="basic:*:userid:password"
#
# this isn't needed. It doesn't do much good anyway. but was in the
# original yi.org script
#
#ip_addr=`netstat -rn | egrep ^0.0.0.0 | sed -e "s,.* ,,g" | \
# xargs /sbin/ifconfig | grep "inet.addr" | sed -e "s,.*addr:,," \
# -e "s, .*,,"`
#
# get the incoming parameter from our perl script from where
# we were launched
#
ip_addr=$1
now=`date`
fetch -q -o /usr/home/dan/fetch_results.html\
http://www.yi.org/bin/dyndns.fcgi?ipaddr=$ip_addr | \
sed -e "s,^,$now: ," -e "s,<.*\?>,,g"
<obtain_ip.pl> #!/usr/bin/perl
#
use Socket;
use MIME::Base64;
# ----------------------------------------------------------------------
# globals
# ----------------------------------------------------------------------
$routerAddress = "192.168.1.254";
$username = "blank";
$password = "Telecom";
$NotifyByMail = "root, yourname\@yourdomain.com";
$EmptyIP = "0.0.0.0";
$IPFilename = "/usr/home/dan/myip.txt";
$DNSUpdateScript = "/usr/home/dan/dns_fetch.sh";
$DNSUpdateResults = "/usr/home/dan/fetch_results.html";
# ----------------------------------------------------------------------
# syslog
# ----------------------------------------------------------------------
sub syslog( $ )
{
my $msg = shift( @_ );
system("logger -i -t DYDNS $msg");
}
# ----------------------------------------------------------------------
# FetchM10Address
# ----------------------------------------------------------------------
sub FetchM10Address()
{
my $encoded;
my $httpRequest;
my $httpResponse;
my $sin;
$encoded = encode_base64( "$username:$password" );
$httpRequest = "GET /shell/show+ip+interfaces HTTP 1.0\r\n"
. "Accept: text/*, text/html\r\n"
. "Authorization: Basic $encoded\r\n"
. "\r\n";
$httpResponse = "";
socket( SH, PF_INET, SOCK_STREAM, getprotobyname('tcp') )
|| die "can not create socket, $!\n";
$sin = sockaddr_in( 80, inet_aton($routerAddress) );
connect( SH, $sin ) || die "can not connect to router, $!\n";
send( SH, $httpRequest, 0 );
while (
|