#!/usr/local/bin/perl # Change this to the location of your krb5.conf file my $krb = "/my/dir/krb5.conf"; use LWP; use File::Copy; # address that tells you your IP address my $url = "http://www.myipaddress.com";; # get a new agent my $agent = LWP::UserAgent->new; # format request my $request = HTTP::Request->new(GET => $url); # get web page my $response = $agent->request($request); # check results $response->is_success or die "$url: ", $response->message,"\n"; # parce answer @parts = split /\n/, $response->content; $ipaddress = ""; foreach $_ (@parts) { if (/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) { warn "Found MULTIPLE copies of IP address. Probably not good\n" if ($ipaddress); $ipaddress = $1; warn "Found IP address $ipaddress\n"; } } die "Couldn't find your IP address. Sorry\n" unless ($ipaddress); # copy old file to .bak copy ($krb, "$krb.bak"); open (SOURCE, "$krb.bak") or die; open (TARGET, ">$krb") or die; while () { # update proxy_gateway line if (/^\s+proxy_gateway/i) { print TARGET " proxy_gateway = $ipaddress\n"; } else { print TARGET; } print TARGET; }