/[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 296 - (show annotations)
Wed Aug 26 11:42:33 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 775 byte(s)
power_up by IP or MAC
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
11 sub power_on {
12 my $target = shift;
13
14 my ( $port, $mac, $ip ) = ( 9 );
15
16 if ( $target =~ m/$RE{net}{MAC}{-keep}/ ) {
17 $mac = $1;
18 $ip = client::ip_from_mac $1;
19 } elsif ( $target =~ m/$RE{net}{IPv4}{-keep}/ ) {
20 $ip = $1;
21 $mac = client::mac_from_ip $1;
22 } else {
23 die "$target isn't IP or MAC";
24 }
25
26 warn "# power_on $ip $mac";
27
28 my $sock = IO::Socket::INET->new( Proto=>'udp' );
29 my $ip_addr = inet_aton($ip);
30 my $sock_addr = sockaddr_in($port, $ip_addr);
31 $mac =~ s{:}{}g;
32
33 my $packet = pack('C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $mac x 16);
34
35 setsockopt($sock, SOL_SOCKET, SO_BROADCAST, 1);
36 send($sock, $packet, 0, $sock_addr);
37 close ($sock);
38 }
39
40 1;

  ViewVC Help
Powered by ViewVC 1.1.26