/[pxelator]/lib/PXElator/wol.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/wol.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 297 - (show annotations)
Wed Aug 26 12:43:47 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 743 byte(s)
send wake-on-lan packet to network broadcast address
because machines which are off won't respond to arp
requests if we try to send to their's IP address directly

1 package wol;
2
3 use warnings;
4 use strict;
5
6 use IO::Socket::INET;
7 use Regexp::Common qw/net/;
8
9 use client;
10 use server;
11
12 sub power_on {
13 my $target = shift;
14
15 my ( $port, $mac ) = ( 9 );
16
17 if ( $target =~ m/$RE{net}{MAC}{-keep}/ ) {
18 $mac = $1;
19 } elsif ( $target =~ m/$RE{net}{IPv4}{-keep}/ ) {
20 $mac = client::mac_from_ip $1;
21 } else {
22 die "$target isn't IP or MAC";
23 }
24
25 warn "# power_on $mac";
26
27 my $sock = IO::Socket::INET->new( Proto=>'udp' );
28 my $ip_addr = inet_aton($server::bcast);
29 my $sock_addr = sockaddr_in($port, $ip_addr);
30 $mac =~ s{:}{}g;
31
32 my $packet = pack('C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $mac x 16);
33
34 setsockopt($sock, SOL_SOCKET, SO_BROADCAST, 1);
35 send($sock, $packet, 0, $sock_addr);
36 close ($sock);
37 }
38
39 1;

  ViewVC Help
Powered by ViewVC 1.1.26