home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _b420336ea867fc5e2d4f7921d1a20293 < prev    next >
Encoding:
Text File  |  2004-06-01  |  1.9 KB  |  89 lines

  1. package PPM::Sysinfo;
  2. $VERSION = '3.00';
  3.  
  4. use strict;
  5. use Data::Dumper;
  6. use PPM::Config;
  7. use Digest::MD5 qw(md5_hex);
  8.  
  9. # The hostname of the currently running machine
  10. sub hostname {
  11.     my $hostname;
  12.     if ($^O eq 'MSWin32') {
  13.     $hostname = (gethostbyname('localhost'))[0];
  14.     }
  15.     elsif (eval { require Net::Domain }) {
  16.     $hostname = Net::Domain::hostfqdn();
  17.     }
  18.     elsif (eval { require Sys::Hostname }) {
  19.     $hostname = Sys::Hostname::hostname();
  20.     }
  21.     else {
  22.     $hostname = "localhost";
  23.     }
  24.     $hostname;
  25. }
  26.  
  27. # The IP address of the currently-running machine
  28. sub ip_addr {
  29.     my @matches;
  30.     my $ip_addr = '0.0.0.0';
  31.     my $ip_raw  = $^O eq 'MSWin32' ? `ipconfig` : `/sbin/ifconfig -a`;
  32.     if ($^O eq 'MSWin32') {
  33.     @matches = ($ip_raw =~ /((?:\d+\.){3}\d+)/g);
  34.     }
  35.     elsif ($^O eq 'solaris') {
  36.     @matches = ($ip_raw =~ /inet ((?:\d+\.){3}\d+)/ig);
  37.     }
  38.     else {
  39.     @matches = ($ip_raw =~ /inet addr:((?:\d+\.){3}\d+)/ig);
  40.     }
  41.     for (@matches) {
  42.     next if $_ eq '0.0.0.0';
  43.     $ip_addr = $_;
  44.     last;
  45.     }
  46.     $ip_addr;
  47. }
  48.  
  49. # The login id of the current user
  50. sub username {
  51.     return getlogin;
  52. }
  53.  
  54. # The install key (generates one if it doesn't exist)
  55. sub inst_key {
  56.     my $f = PPM::Config::load_config_file('instkey', 'ro');
  57.     unless (defined $f->{DATA}{inst_id}) {
  58.     $f = PPM::Config::load_config_file('instkey', 'rw');
  59.     $f->{DATA} = generate_inst_key();
  60.     goto &inst_key;
  61.     }
  62.     $f->{DATA}{inst_id};
  63. }
  64.  
  65. sub generate_inst_key {
  66.     my $DATA = {
  67.     hostname => hostname(),
  68.     os       => $^O,
  69.     date     => scalar localtime,
  70.     randkey     => rand,
  71.     };
  72.     $DATA->{inst_id} = md5_hex(
  73.     join':', @$DATA{qw(randkey hostname os date)}
  74.     );
  75.     $DATA;
  76. }
  77.  
  78. sub generate_user_key {
  79.     my $f = PPM::Config::load_config_file('instkey', 'ro');
  80.     my $user = username();
  81.     my $host = hostname();
  82.     my $time = $f->{DATA}{date};
  83.     Digest::MD5::md5_hex("$user:$host:$time");
  84. }
  85.  
  86. 1;
  87.  
  88. __DATA__
  89.