#!/usr/bin/perl -w # Switch Script written by Ali RB 28th March 2000 ################################################## # This script parses a file /etc/switch.conf # Syntax for this file is: # host name colon separated MAC address e.g. # p001 00:50:BA:D2:A7:19 # Only an excerpt is listed here, for the whole # script see resources # This routine generates a magic packet to switch # on a particular machine # Input is a colon separated Hexadecimal MAC address # of the target machine # and the return value is the Magic Packet to be # broadcast on the network to # switch it on. Usage: $mpacket = # generate_magic_packet("11:22:33:44:55:66"); sub generate_magic_packet { <\n> local ($ether) = @_; local $packet=""; local $hexa ="0123456789ABCDEF"; local $i; $ccnt = ($ether =~ tr/://); if (($ccnt != 5) || (length($ether) != 17)) { return "" }; $ccnt = 0; for ($i = 0; $i <18; $i = $i + 3) { my $a = index( $hexa,uc(substr($ether,$i,1))); my $b = index( $hexa,uc(substr($ether,$i+1,1))); if (($a<0)||($b<0)) { return ""}; substr($packet,$ccnt,1) = chr(16 * $a + $b); $ccnt++; } for ($i = 0; $i <4;$i++) { $packet = $packet.$packet;} for ($i = 0; $i <6;$i++) { $packet = chr(255).$packet;} return $packet; }