Invariavelmente eu preciso trocar o hostid de uma máquina com Solaris para realizar testes.  O objetivo não é pirataria, ou algo assim, mas testes de verificação de aplicativos com licença de uso, que são amarrados ao hostid da máquina.

Eu conhecia um programa para fazer isso, mas essa semana topei com uma explicação bem legal de como fazer manualmente a mudança, disponível aqui: 

How to Change the Hostid of a Sun Solaris Machine?

Baseado nessa explicação, montei um programa em perl pra conseguir fazer a mesma coisa de forma mais simplificada, o hostid.pl.


#! /usr/bin/perl

$HOSTID = "/usr/bin/hostid";
$SAVEORIG = "/etc/hostid.orig";
$ADB = "/usr/bin/adb";
$ADBOPTS = "-w -k /dev/ksyms /dev/mem";


sub Usage() {
  print "Use: $0 \n";
  print "\t note: hostid must be 8 chars long\n";
  exit(1);
}

if ($ENV{"USER"} ne "root") {
  print "This must be run as root.\n";
  exit(1);
}

$newhostid = $ARGV[0];
if (length($newhostid) != 8) {
  Usage();
}

if (! -f "$SAVEORIG") {
  print "Saving original hostid into $SAVEORIG\n";
  open(SAVE,">$SAVEORIG") or die "Impossible to save original hostid: $!\n";
  print SAVE `$HOSTID`;
  close SAVE;
}

$myhex = eval("0x".$newhostid);
$mystr = sprintf("%s", $myhex);

$i = 0;
$parts[$i] = substr($mystr, $i, 4);
$parts[$i + 1] = substr($mystr, $i + 4, 4);
$parts[$i + 2] = substr($mystr, $i + 8, 4);

for ($i = 0; $i <= 3; $i++) {
  foreach $p (split(//,$parts[$i])) {
	$hwserial[$i] .= ($p + 30);
  }
}
$hwserial[2] .= "0000";

$msg = "$ADB $ADBOPTS << EOF > /dev/null

hw_serial/W 0x".$hwserial[0]."
hw_serial+4/W 0x".$hwserial[1]."
hw_serial+8/W 0x".$hwserial[2]."
END

EOF
";
print "Applying hostid change into memory\n";
system($msg);
print "Enforcing new hostid across system\n";
system("/etc/rc2.d/S20sysetup");
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.