--- loncom/lonnet/perl/lonnet.pm 2007/03/30 18:18:43 1.855 +++ loncom/lonnet/perl/lonnet.pm 2007/04/03 00:48:33 1.856 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.855 2007/03/30 18:18:43 albertel Exp $ +# $Id: lonnet.pm,v 1.856 2007/04/03 00:48:33 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -7589,6 +7589,7 @@ sub goodbye { } BEGIN { + # ----------------------------------- Read loncapa.conf and loncapa_apache.conf unless ($readit) { { @@ -7761,6 +7762,8 @@ sub get_dns { { my %iphost; + my %name_to_ip; + my %lonid_to_ip; sub get_hosts_from_ip { my ($ip) = @_; my %iphosts = &get_iphost(); @@ -7769,10 +7772,25 @@ sub get_dns { } return; } + + sub get_host_ip { + my ($lonid) = @_; + if (exists($lonid_to_ip{$lonid})) { + return $lonid_to_ip{$lonid}; + } + &logthis(" looking ip $lonid ...."); + my $name=&hostname($lonid); + my $ip = gethostbyname($name); + return if (!$ip || length($ip) ne 4); + $ip=inet_ntoa($ip); + $name_to_ip{$name} = $ip; + $lonid_to_ip{$lonid} = $ip; + return $ip; + } sub get_iphost { if (%iphost) { return %iphost; } - my %name_to_ip; + &logthis(" getting ips ...."); my %hostname = &all_hostnames(); foreach my $id (keys(%hostname)) { my $name=$hostname{$id}; @@ -7788,6 +7806,7 @@ sub get_dns { } else { $ip = $name_to_ip{$name}; } + $lonid_to_ip{$id} = $ip; push(@{$iphost{$ip}},$id); } return %iphost;