Date: Sat, 6 Jan 2001 19:13:45 -0800 (PST) From: Peter Jones <pjones@pmade.org> To: G D McKee <freebsd@gdmckee.com> Cc: freebsd-questions <freebsd-questions@FreeBSD.ORG> Subject: Re: Neoupdate Message-ID: <Pine.BSF.4.21.0101061909310.54906-200000@pmade.org> In-Reply-To: <000b01c0781f$aec46640$0500a8c0@gdmckee.local>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
Here is a snip of code that I use to update yi.org:
sub ip_get
{
my $cmd = '/sbin/ifconfig tun0';
my $data = `$cmd`;
if ($data =~ /inet\s+((?:\d+|\.)+)/) {
return $1;
} else {
exit 1;
}
}
I have also attached the entire script.
On Sat, 6 Jan 2001, G D McKee wrote:
> Hi
>
> Found a useful program to update your DNS if you are on a cable modem but
> the reg ex only seems to work with Linux. Does any one know how to get it
> to work with FreeBSD.
>
> The Code that is a fault is as follows:
>
> sub getip(){
> ($device) = @_;
> my(@newip,$newip,$nic);
> $nic = qx(/sbin/ifconfig $device);
> print "$nic\n";
> @newip = grep(/^addr/, split(/\s/, $nic));
> $newip = $newip[0];
> $newip =~ s/addr://;
> if ($newip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/){
> return $newip;
> }else{
> die "Aborting : Can't retrieve ip information from $device\n";
> }
> }
>
> Has any one got any ideas on how to get this to work with device tun0 and a
> standard nic.
>
> G D McKee
>
>
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
>
--
.......................................................................
: Peter Jones : Unix Geek - Four Wheeling :
: pjones@pmade.org : Code Writing - Jesus Freak :
:....................................:................................:
:echo er|perl -0160 -pe ';$;=ord$/;s;^;"\U$/".chr($\;-11).chr$\;+4;e;':
:.....................................................................:
[-- Attachment #2 --]
#! /usr/bin/perl -w
################################################################################
#
# yiupdate (Update your IP on yi.org)
#
################################################################################
#
# Includes
#
################################################################################
use strict;
use HTTP::Request;
use LWP::UserAgent;
################################################################################
#
# Constants
#
################################################################################
#---- Configuration Options ----------------------#
use constant YI_USERNAME => 'your-username';
use constant YI_PASSWORD => 'your-password';
use constant YI_INTERFACE => 'tun0';
#---- End Configuration Options ------------------#
use constant YI_URL => 'http://www.yi.org/bin/dyndns.fcgi';
use constant IFCONFIG => '/sbin/ifconfig';
################################################################################
#
# Global Variables and Default Settings
#
################################################################################
use vars qw($VERSION $DATE $ID);
$VERSION = '0.01';
$DATE = 'Wed Apr 26 19:14:00 2000';
$ID = '$Id: yiupdate,v 1.1.1.1 2000/04/27 03:02:13 pjones Exp $';
my ($ua, $req, $resp, $ip);
################################################################################
#
# Code Start
#
################################################################################
$ip = ip_get();
$ua = new LWP::UserAgent;
$ua->agent("yiupdate/$VERSION");
$req = new HTTP::Request GET => YI_URL;
$req->authorization_basic(YI_USERNAME, YI_PASSWORD);
$req->url->query("ipaddr=$ip");
$resp = $ua->request($req);
unless ($resp->is_success) {
print STDERR "yiupdate: error sending request to webserver\n";
print STDERR "yiupdate: " . $resp->status_line . "\n";
print STDERR "yiupdate: aborting\n";
exit 1;
}
unless ($resp->content =~ /STATUS:OK/) {
print STDERR "yiupdate: yi.org returned an error\n";
exit 1;
}
################################################################################
#
# ==== ip_get ==== #############################################################
#
# Arguments:
# None
#
# Returns:
# The IP Address for the Interface YI_INTERFACE
#
# Description:
# Tries to get your IP Address
#
################################################################################
sub ip_get
{
my $cmd = IFCONFIG . ' ' . YI_INTERFACE;
my $data = `$cmd`;
if ($data =~ /inet\s+((?:\d+|\.)+)/) {
return $1;
} else {
print STDERR "yiupdate: I can't figure out what your IP Address is\n";
print STDERR "yiupdate: the command that I used is ...\n";
print STDERR "yiupdate: $cmd\n";
print STDERR "yiupdate: I was looking for 'inet' but this is what I had to work with\n";
print STDERR "$data\n";
print STDERR "yiupdate: aborting\n";
exit 1;
}
} # <-- End ip_get -->
################################################################################
# END-OF-SCRIPT #
################################################################################
=head1 NAME
yiupdate
=head1 DESCRIPTION
Updates your IP address with yi.org
It is desiged to run on Unix, or a Unix like OS that supports ifconfig.
It is written in Perl and I recomend (reccomend) that you use 5.5.3
(5.005_003) or later. You will also need to have the LWP Perl module
installed. If you don't, then try this command ...
perl -MCPAN -e 'install("LWP")'
=head1 CONFIGURATION
To configure yiupdate, crack it open in your favorite text editor.
The three configuration constants are YI_USERNAME, YI_PASSWORD and
YI_INTERFACE.
YI_USERNAME is your yi username
YI_PASSWORD is your yi password
YI_INTERFACE is the interface to get your ip from to send to yi.org. For
example, if you are using FreeBSD and ppp then you would set this to tun0
to get the inet address for the tunnel interface.
=head1 EXAMPLES
yiupdate
=head1 SEE ALSO
perl(1)
http://www.yi.org
=head1 AUTHOR
Peter J Jones
p@dancris.com
=cut
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0101061909310.54906-200000>
