Subversion Repositories HomeAutomation

Rev

Rev 1040 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #!/usr/bin/perl
  2.  
  3. # Written by Mattias Runge 20089
  4.  
  5. use IO::Socket;
  6.  
  7. $| = 1;
  8.  
  9. $numArgs = $#ARGV + 1;
  10.  
  11. my $hostname = "localhost";
  12. my $port = 1202;
  13. my $filename = "";
  14. my $hwid = "";
  15. my $bios = "false";
  16.  
  17. foreach $argnum (0 .. $#ARGV)
  18. {
  19.     if ($ARGV[$argnum] eq "-h")
  20.     {
  21.         $hostname = $ARGV[$argnum+1];
  22.     }
  23.     elsif ($ARGV[$argnum] eq "-p")
  24.     {
  25.         $port = $ARGV[$argnum+1];
  26.     }
  27.     elsif ($ARGV[$argnum] eq "-i")
  28.     {
  29.         $hwid = $ARGV[$argnum+1];
  30.     }
  31.     elsif ($ARGV[$argnum] eq "-f")
  32.     {
  33.         $filename = $ARGV[$argnum+1];
  34.     }
  35.     elsif ($ARGV[$argnum] eq "-b")
  36.     {
  37.         $bios = "true";
  38.     }
  39. }
  40.  
  41. if ($filename eq "")
  42. {
  43.     print "You must specify a file!\n";
  44.     exit 1;
  45. }
  46. elsif ($hwid eq "")
  47. {
  48.     die "You must specify a hardware id!\n";
  49.     exit 1;
  50. }
  51.  
  52. #0x14f90d1f to 0x1f0df914
  53. @hwidChars = split(//, $hwid);
  54. $hwid = @hwidChars[0]. @hwidChars[1]. @hwidChars[8]. @hwidChars[9]. @hwidChars[6]. @hwidChars[7]. @hwidChars[4]. @hwidChars[5]. @hwidChars[2]. @hwidChars[3];
  55.  
  56. open(FILE, $filename) || die("Could not open file!");
  57. @fileData=<FILE>;
  58. close(FILE);
  59.  
  60. my $sock = new IO::Socket::INET(
  61.                 PeerAddr => $hostname,
  62.                 PeerPort => $port,
  63.                 Proto => 'tcp'
  64.                 );
  65. die "Could not create socket: $!\n" unless $sock;
  66.  
  67. sleep(1);
  68.  
  69. print $sock "programNode('", $hwid, "','";
  70.  
  71. foreach $line (@fileData)
  72. {
  73.     print $sock $line;
  74. }
  75.  
  76. print $sock "', ", $bios, ");\n";
  77.  
  78. while (1)
  79. {
  80.     $sock->recv($text, 128);
  81.    
  82.     if (rindex($text, "STOP") ne -1)
  83.     {
  84.         print "\n";
  85.         exit 0;
  86.     }
  87.     elsif ($text ne '')
  88.     {
  89.         print $text;
  90.     }
  91.     else
  92.     {
  93.         print "Connection closed by other side!";
  94.         exit 0;
  95.     }
  96. }
  97.  
  98. close($sock);
  99.