[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 03 Apr 2007 00:48:34 -0000


albertel		Mon Apr  2 20:48:34 2007 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - able to get ip for a lonid
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.855 loncom/lonnet/perl/lonnet.pm:1.856
--- loncom/lonnet/perl/lonnet.pm:1.855	Fri Mar 30 14:18:43 2007
+++ loncom/lonnet/perl/lonnet.pm	Mon Apr  2 20:48:33 2007
@@ -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 @@
 }
 
 BEGIN {
+
 # ----------------------------------- Read loncapa.conf and loncapa_apache.conf
     unless ($readit) {
 {
@@ -7761,6 +7762,8 @@
 
 { 
     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 @@
 	}
 	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 @@
 	    } else {
 		$ip = $name_to_ip{$name};
 	    }
+	    $lonid_to_ip{$id} = $ip;
 	    push(@{$iphost{$ip}},$id);
 	}
 	return %iphost;