pax_global_header00006660000000000000000000000064141466001130014506gustar00rootroot0000000000000052 comment=182e6cdd2a4b90e0db6c265f266a40262bbab38b wakeonlan-0.42/000077500000000000000000000000001414660011300134125ustar00rootroot00000000000000wakeonlan-0.42/.gitignore000066400000000000000000000000471414660011300154030ustar00rootroot00000000000000/MYMETA.* /Makefile /blib/ /pm_to_blib wakeonlan-0.42/Changes000066400000000000000000000035031414660011300147060ustar00rootroot00000000000000Revision history for Perl script wakeonlan. 0.10 2000-04-19 ico@edd.dhs.org - Initial release. This works for me... - Tested with 3Com 3c905B Cyclone 100baseTx 0.20 2000-04-23 ico@edd.dhs.org - Major bugfix. When the called system is not known in the ARP-table, no packets are sent. Solved by allowing broadcast-addresses. Use broadcast address as IP and all should work.... (Thanks to Egon Kastelijn for making the problem clear to me ) 0.30 2000-07-01 ico@edd.dhs.org - Some cleaning done by Jose Pedro Oliveira : 1. Forced variable declaration with the pragma 'use strict' 2. Removed the bind call (we don't expect to receive any reply) 3. Simplified the packet generation 0.31 2000-07-17 ico@edd.dhs.org - Changes made by Jose Pedro Oliveira 1. Changed the destination port from the echo (7) to the discard port (9) in order to avoid the reply from an awaken computer with an active echo service. 2. Removed variables $laddr and $me 3. Closed the socket 4. Added the variable $VERSION 5. Added a link in the README file of the Whitepaper subdirectory - Other changes : 6. Completer checks for valid HW-address (Ico Doornekamp) 7. Fixed wrong return value on 'die' (Oliver Jones) 0.32 2000-07-23 jpo@di.uminho.pt - created by h2xs 1.19 ($ h2xs -A -X -n wakeonlan) - not released 0.40 2000-08-01 jpo@di.uminho.pt - New command line parameters - Ability to load ethernet addresses from file 0.41 2005-01-27 jpo@di.uminho.pt - Minor documentation updates (including several typo corrections). 0.42 2021-11-22 jose.p.oliveira.oss@gmail.com - Update project page - Update main maintainers email address - Minor documentation updates (links) - Test suite (developer) # vim:set ai ts=4 sw=4 sts=4: wakeonlan-0.42/MANIFEST000066400000000000000000000002211414660011300145360ustar00rootroot00000000000000Changes Makefile.PL MANIFEST README.md wakeonlan examples/lab001.wol t/81_perlcritic.t t/91_pod.t t/92_pod_coverage.t t/93_pod_spell.t SIGNATURE wakeonlan-0.42/META.yml000066400000000000000000000004471414660011300146700ustar00rootroot00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: wakeonlan version: 0.41 version_from: wakeonlan installdirs: site requires: distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 wakeonlan-0.42/Makefile.PL000066400000000000000000000024461414660011300153720ustar00rootroot00000000000000use strict; use warnings; use v5.10.1; # ExtUtils::MakeMaker 6.46+ for META_MERGE support use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'wakeonlan', 'VERSION_FROM' => 'wakeonlan', 'ABSTRACT' => "Script to send 'magic packets' to wakeable computers", 'AUTHOR' => 'José Pedro Oliveira ', 'LICENSE' => 'perl', 'INSTALLDIRS' => 'site', 'EXE_FILES' => ['wakeonlan'], 'PREREQ_PM' => {}, 'TEST_REQUIRES' => { 'Test::More' => 0, 'Test::Pod::Coverage' => '1.00', 'Test::Pod' => '1.00', 'Test::Spelling' => 0, 'Test::Perl::Critic' => 0, }, 'NO_META' => 1, 'NO_MYMETA' => 1, # META_MERGE requires ExtUtils::MakeMaker 6.46+ 'META_MERGE' => { 'meta-spec' => { version => 2 }, 'resources' => { 'repository' => { 'type' => 'git', 'url' => 'https://github.com/jpoliv/wakeonlan.git', 'web' => 'https://github.com/jpoliv/wakeonlan', }, 'bugtracker' => { 'web' => 'https://github.com/jpoliv/wakeonlan/issues', }, }, }, ); # vim:set ai ts=4 sw=4 sts=4 et syntax=perl: wakeonlan-0.42/README.md000066400000000000000000000104331414660011300146720ustar00rootroot00000000000000# wakeonlan This is some premature documentation for this project. Feel free to contact with comments or additions (good or bad). Authors: * José Pedro Oliveira ~~~~ * Ico Doornekamp Table of contents: 1. [What is wakeonlan](#1-what-is-wakeonlan) 2. [How does WOL work?](#2-how-does-wol-work) 3. [How is it implemented here?](#3-how-is-it-implemented-here) 4. [Known to work hardware](#4-known-to-work-hardware) 5. [References](#5-references) ## 1. What is wakeonlan This script sends 'magic packets' to wake-on-lan enabled ethernet adapters, in order to switch on the called PC. ## 2. How does WOL work? WOL is based on the following principle : When the PC shuts down, the NIC still gets power, and keeps listening on the network for a 'magic' packet to arrive. This packet must contain a certain byte-sequence, but can be encapsulated in any kind of packet (IPX, IP, anything). Take a look at the code for the magic sequence. This program uses UDP for sending the packet. The complete UDP packet, sent over an ethernet interface, looks something like this ```text [Ethernet header][IP header][UDP header][Magic sequence][CRCS] ``` The only goal of the script is to send this packet over the network. It expects no returning data, since the NIC only listens, and does not reply anything. For a more detailed description of the Magic Packet technology, check the AMD resources listed in the [references](#5-references) section. ## 3. How is it implemented here? The scripts takes 2 arguments, the MAC-address of the NIC, and an IP address. The IP-address is tricky : For a NIC on your local subnet, use the broadcast-address of this subnet. (e.g. subnet 192.168.10.0 with netmask 255.255.255.0, use 192.168.10.255) For waking up a PC on a network behind one or more routers, some tricks must be used. When the routers forward directed subnet broadcasts, it is possible to use the broadcast address of the destination network. The problem is that many routers don't forward broadcast packets, so the packet will never arrive at the network. It is possible to send the packet to the remote net however, by sending it to the IP address of another host on that network that's alive at that moment. The remote hosts will probably ignore the packet, but it has been seen by the listening NIC that's also on the same subnet, and it will turn on the computer... Feel free to experiment on this. ## 4. Known-to-work hardware * 3Com 3c905B Cyclone 100baseTx on an Abit BP6 Motherboard; (Ico Doornekamp) * Intel EtherExpress Pro (i82557) with management chip built onto an IBM IntelliStation motherboard; (Sean-Paul Rees) * Intel EtherExpress PRO/100+ (chipset 82559) with a PXE boot agent on an ASUS P2B motherboard; (José Pedro Oliveira) * Motherboard: ASUS TUSL2-C; BIOS: Award BIOS / Power / Power Up Control / Wake On LAN or PCI Modem [Enable]; Network card: Intel Pro/100 S Desktop Adapter (chipset 82550) with PXE boot agent v4.0.22; (José Pedro Oliveira) * Motherboard: ASUS TUSL2-C; BIOS: Award BIOS / Power / Power Up Control / Wake On LAN or PCI Modem [Enable] Network card: 3Com Fast Etherlink TX 10/100 PCI (3C905C-TXM) with Managed PC Boot Agent (MBA) v4.30 (build 3) Pre-boot eXecution Environment (PXE) v2.20; (José Pedro Oliveira) * nVidia Corporation nForce2 Ethernet Controller on ASUS and EPOX motherboards; (Antoniu-George) * Macs: All Powerbooks; Energy Prefs: Wake on ethernet network Administrator access; (Denis Ahrens) ## 5. References * [AMD - Magic Packet Technology](https://web.archive.org/web/20000414213425/http://www.amd.com/products/npd/overview/20212.html) - Internet Archive link * [AMD - Magic Packet Technology - White paper](https://www.amd.com/system/files/TechDocs/20213.pdf) * [Wireshark wiki - WakeOnLan](https://gitlab.com/wireshark/wireshark/-/wikis/WakeOnLan) * [Wikipedia - Wake-On-LAN](https://en.wikipedia.org/wiki/Wake-on-LAN) * [Old wakeonlan project page](https://web.archive.org/web/20140120212300/http://gsd.di.uminho.pt:80/jpo/software/wakeonlan/) - Internet Archive link * [Old Wake on LAN mini HOWTO](https://web.archive.org/web/20080321144028/http://gsd.di.uminho.pt/jpo/software/wakeonlan/mini-howto/wol-mini-howto.html) - Internet Archive link wakeonlan-0.42/SIGNATURE000066400000000000000000000031261414660011300147000ustar00rootroot00000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.87. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 SHA256 23e5d48ddcfe2ca18d1b4b5f90a296e81abc7d9bd91cc193145e25508d9d7fbc Changes SHA256 1c648e7b6bffecf1aa79bd0f9671e15d63f669dbe5d6cddf0da659d339fd887e MANIFEST SHA256 52f20c3720e76a321e088728403317500f8628ea8d1420719a1d68b2791a286a Makefile.PL SHA256 c602240dcdc4d21f17330d5891975f15d49b59d7badd7d307929f3fbba1a92a7 README.md SHA256 d1277f55decc6ddd4e542d3eaeca7e7018f6890bf7068c97d6ce0bcd004024ca examples/lab001.wol SHA256 178958ed88487b2425e161ab425ef4a98ef56950e180d8a4ae1f9843cf4b18f9 t/81_perlcritic.t SHA256 6f0a33f6ef18a18e7e4593b672879ae5b35042f5bc63956bcf07d05339a5bea3 t/91_pod.t SHA256 2ffba038e8a2cf9280d42f847f74ac00b7426182c52e66eb28b3ade1618e9580 t/92_pod_coverage.t SHA256 03e56ed406a0fc22701cc59cecf4a1a54974d6c2fdfaef2532db95c20c420994 t/93_pod_spell.t SHA256 63f97ff7b09fc63c1b52f2f156e6f72ff76b7131371d193aba698e2819a33bb1 wakeonlan -----BEGIN PGP SIGNATURE----- iHUEARYDAB0WIQQQwFsom3jQZ+/KFNTdfhW5/LYVNgUCYZr/+gAKCRDdfhW5/LYV NhTCAQDdtP2jiPsJmfHcUtGGIrsmAvtkIjxsz4W9EgyXb+DO2QD7B4wf2cxoDHC9 XcpKQCOqs9g0B9HP0RREpgjf20kXQwM= =sGxS -----END PGP SIGNATURE----- wakeonlan-0.42/examples/000077500000000000000000000000001414660011300152305ustar00rootroot00000000000000wakeonlan-0.42/examples/lab001.wol000066400000000000000000000011421414660011300167300ustar00rootroot00000000000000# # This an example of a text file containing hardware addresses # # File structure # -------------- # - blank lines are ignored # - comment lines are ignored (lines starting with a hash mark '#') # - other lines are considered valid records and can have 3 columns: # # Hardware address, IP address, destination port # # the last two are optional, in which case the following defaults # are used: # # IP address: 255.255.255.255 (the limited broadcast address) # port: 9 (the discard port) # 01:02:03:04:05:06 192.168.1.255 9 07:09:09:0A:0B:0C 255.255.255.255 0D:0E:0F:00:10:11 wakeonlan-0.42/packaging/000077500000000000000000000000001414660011300153365ustar00rootroot00000000000000wakeonlan-0.42/packaging/fedora/000077500000000000000000000000001414660011300165765ustar00rootroot00000000000000wakeonlan-0.42/packaging/fedora/wakeonlan.spec000066400000000000000000000033411414660011300214320ustar00rootroot00000000000000Name: wakeonlan Version: 0.42 Release: 1%{?dist} Summary: Perl script to wake up computers through Magic Packets License: Artistic URL: https://github.com/jpoliv/wakeonlan/ Source0: https://github.com/jpoliv/wakeonlan/archive/%{name}-%{version}/%{name}-%{version}.tar.gz BuildArch: noarch BuildRequires: make BuildRequires: perl-generators BuildRequires: perl-interpreter BuildRequires: perl(ExtUtils::MakeMaker) BuildRequires: perl(warnings) BuildRequires: perl(strict) # Test suite BuildRequires: perl(Test::More) BuildRequires: perl(Test::Perl::Critic) BuildRequires: perl(Test::Pod) BuildRequires: perl(Test::Pod) BuildRequires: perl(Test::Spelling) Requires: perl(:MODULE_COMPAT_%(eval "`perl -V:version`"; echo $version)) %description This script sends 'magic packets' to wake-on-lan enabled ethernet adapters and motherboards, in order to switch on the called PC. %prep %setup -q %build %{__perl} Makefile.PL INSTALLDIRS=vendor make %{?_smp_mflags} %install make pure_install DESTDIR=%{buildroot} find %{buildroot} -type f -name .packlist -delete %{_fixperms} -c %{buildroot} %check make test %files %defattr(-,root,root,-) %doc Changes README.md examples/ %{_bindir}/* %{_mandir}/man1/*.1* %changelog * Mon Nov 22 2021 Jose Pedro Oliveira - 0.42-1 - Update to 0.42. - Update specfile to follow recent Fedora's packaging guidelines (https://docs.fedoraproject.org/en-US/packaging-guidelines/Perl/) * Tue Nov 19 2013 Jose Pedro Oliveira - 0.41-1 - Drop deprecated packaging guidelines (from fedora.us days) * Fri Jan 28 2005 Jose Pedro Oliveira - 0:0.41-0.fdr.1 - Update to 0.41. * Tue Jun 08 2004 Jose Pedro Oliveira - 0:0.40_09-0.fdr.1 - First build. wakeonlan-0.42/t/000077500000000000000000000000001414660011300136555ustar00rootroot00000000000000wakeonlan-0.42/t/81_perlcritic.t000066400000000000000000000002311414660011300165060ustar00rootroot00000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 1; use Test::Perl::Critic; critic_ok('wakeonlan'); # vim:set ai ts=4 sw=4 sts=4 et syntax=perl: wakeonlan-0.42/t/91_pod.t000066400000000000000000000003201414660011300151300ustar00rootroot00000000000000#!/usr/bin/perl -w use strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); # vim:set ai ts=4 sw=4 sts=4 et syntax=perl: wakeonlan-0.42/t/92_pod_coverage.t000066400000000000000000000003601414660011300170100ustar00rootroot00000000000000#!/usr/bin/perl -w use strict; use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); # vim:set ai ts=4 sw=4 sts=4 et syntax=perl: wakeonlan-0.42/t/93_pod_spell.t000066400000000000000000000006451414660011300163430ustar00rootroot00000000000000#!/usr/bin/perl -w use strict; use Test::More; use Test::Spelling; add_stopwords(qw(José Oliveira)); add_stopwords(qw(Ico Doornekamp)); add_stopwords(qw(ARP IP UDP NIC)); add_stopwords(qw(lan ethernet subnet)); add_stopwords(qw(subdirectory)); add_stopwords(qw(WOL wol wakeonlan wakeable)); add_stopwords(qw(0xFF)); add_stopwords(qw(lab001)); all_pod_files_spelling_ok(); # vim:set ai ts=4 sw=4 sts=4 et syntax=perl: wakeonlan-0.42/wakeonlan000077500000000000000000000171441414660011300153260ustar00rootroot00000000000000#!/usr/bin/perl -w use strict; use Socket; use Getopt::Long; use Pod::Usage; our $VERSION = '0.42'; use constant { PORT_MIN => 0, PORT_MAX => 65535, }; # # Hardware address formats # our @hwaddr_regexs = ( # xx:xx:xx:xx:xx:xx (canonical) '^(?:[\da-f]{1,2}:){5}[\da-f]{1,2}$', # xx-xx-xx-xx-xx-xx (Windows) '^(?:[\da-f]{1,2}-){5}[\da-f]{1,2}$', # xxxxxx-xxxxxx (Hewlett-Packard switches) '^[\da-f]{6}-[\da-f]{6}$', # xxxxxxxxxxxx (Intel Landesk) '^[\da-f]{12}$', ); my $DEFAULT_IP = '255.255.255.255'; my $DEFAULT_PORT = getservbyname('discard', 'udp'); my $verbose = 1; my $dryrun = 0; my $filename = ''; my @queue = (); my %stats = ( total => 0, valid => 0, invalid => 0, sent => 0, ); ###################################################################### sub isValidPort { my $port = shift; return ($port >= PORT_MIN and $port <= PORT_MAX) ? 1 : 0; } sub isValidIPAddress { my $ipaddress = shift; my $t = 0; $t += $_ for map { ($_ <= 255)?1:0 } $ipaddress =~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; return ($t == 4) ? 1 : 0; } sub isValidHardwareAddress { my $hwaddr = shift; foreach my $re (@hwaddr_regexs) { return 1 if ($hwaddr =~ m/$re/i); } return 0; } ###################################################################### sub loadFromCommandLine { for my $arg (@_) { $stats{total}++; if (! isValidHardwareAddress($arg) ) { warn "Invalid hardware address: $arg\n"; $stats{invalid}++; next; } $stats{valid}++; push @queue, [ $arg, $DEFAULT_IP, $DEFAULT_PORT ]; } } sub loadFromFile { my $filename = shift; my ($hwaddr, $ipaddr, $port); open (my $FILE, '<', $filename) or die "open : $!"; while(<$FILE>) { next if /^\s*#/; # ignore comment lines next if /^\s*$/; # ignore empty lines $stats{total}++; chomp; ($hwaddr, $ipaddr, $port) = split; if (! isValidHardwareAddress($hwaddr) ) { warn "Invalid hardware address: $hwaddr\n"; $stats{invalid}++; next; } $ipaddr = $DEFAULT_IP unless defined($ipaddr); if (! isValidIPAddress($ipaddr) ) { warn "Invalid IP address: $ipaddr\n"; $stats{invalid}++; next; } $port = $DEFAULT_PORT unless defined($port); if (! isValidPort($port) ) { warn "Invalid port number: $port\n"; $stats{invalid}++; next; } $stats{valid}++; push @queue, [ $hwaddr, $ipaddr, $port ]; } close $FILE; } ###################################################################### # # wake # # The 'magic packet' consists of 6 times 0xFF followed by 16 times # the hardware address of the NIC. This sequence can be encapsulated # in any kind of packet, in this case an UDP packet targeted at the # discard port (9). # sub wake { my ($sock, $hwaddr, $ipaddr, $port) = @_; my ($raddr, $them, $pkt); # # Expects hardware address in canonical form (xx:xx:xx:xx:xx:xx) # # # Generate the magic sequence # foreach (split /:/, $hwaddr) { $pkt .= chr(hex($_)); } $pkt = chr(0xFF) x 6 . $pkt x 16; # # Send packet # # Patch by Eugenio Jarosiewicz # $raddr = inet_aton($ipaddr); # $raddr = gethostbyname($ipaddr); $them = pack_sockaddr_in($port, $raddr); print "Sending magic packet to $ipaddr:$port with payload $hwaddr\n" if $verbose; #send($sock, $pkt, 0, $them) or die "send : $!"; send($sock, $pkt, 0, $them) unless $dryrun; } sub sendMagicPackets { if (! @queue) { warn "Nothing to do!\n"; return; } my $sock; my $proto = getprotobyname('udp'); socket($sock, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!"; setsockopt($sock, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!"; for my $ref (@queue) { wake($sock, $ref->[0], $ref->[1], $ref->[2]); $stats{sent}++; } close $sock; } ###################################################################### # main ###################################################################### # # Process the command line # GetOptions( "h|help" => sub { pod2usage( -exitval => 0, -verbose => 1); }, "v|version" => sub { print "wakeonlan $VERSION\n"; exit(0); }, "q|quiet" => sub { $verbose = 0; }, "i|ip=s" => \$DEFAULT_IP, "p|port=i" => \$DEFAULT_PORT, "f|file=s" => \$filename, "n|dry-run" => sub { $dryrun = 1; }, ) or pod2usage( -exitval => 1, -verbose => 1); # # Validate information # # if (! isValidPort($DEFAULT_PORT)) { warn "Invalid default port number: $DEFAULT_PORT\n"; exit(2); } if (! isValidIPAddress($DEFAULT_IP)) { warn "Invalid default IP address: $DEFAULT_IP\n"; exit(3); } if ($filename and ! -f $filename) { warn "Invalid filename: $filename\n"; exit(4); } # # Nothing to do ? # if (!$filename and !@ARGV) { pod2usage( -exitval => 0, -verbose => 1); }; # # Load hardware addresses # loadFromCommandLine(@ARGV); loadFromFile($filename) if $filename; # print Dumper(@queue); sendMagicPackets(); # # Print statistics # if ($verbose) { printf "Hardware addresses: \n", $stats{total}, $stats{valid}, $stats{invalid}; printf "Magic packets: \n", $stats{sent}; } exit 0; ########## __END__ # Script documentation =encoding utf8 =head1 NAME wakeonlan - Perl script to wake up computers =head1 SYNOPSIS wakeonlan [-h|--help] [-v|--version] [-q|--quiet] [-n|--dry-run] [-i|--ip IP_address] [-p|--port port] [-f|--file file_name] [[hardware_address] ...] =head1 DESCRIPTION This script sends 'magic packets' to wake-on-lan enabled ethernet adapters and motherboards, in order to switch on the called PC. Be sure to connect the NIC with the motherboard if necessary, and to enable the WOL function in the BIOS. The 'magic packet' consists of 6 times 0xFF followed by 16 times the hardware address of the NIC. This sequence can be encapsulated in any kind of packet. This script uses UDP packets. =head1 OPTIONS =over =item B<-h, --help> Displays the help information. =item B<-v, --version> Displays the script version. =item B<-i, --ip=IP_address> Destination IP address. Unless you have static ARP tables you should use some kind of broadcast address (the broadcast address of the network where the computer resides or the limited broadcast address). Default: 255.255.255.255 (the limited broadcast address). =item B<-p, --port=port> Destination port. Default: 9 (the discard port). =item B<-f, --file=file_name> File with hardware addresses of wakeable computers. For an example check the file lab001.wol in the examples subdirectory. =item B<-q, --quiet> Quiet mode. =item B<-n, --dry-run> Print the commands that would be executed, but do not execute them. =back =head1 EXAMPLES Using the limited broadcast address (255.255.255.255): $ wakeonlan 01:02:03:04:05:06 $ wakeonlan 01:02:03:04:05:06 01:02:03:04:05:07 Using a subnet broadcast address: $ wakeonlan -i 192.168.1.255 01:02:03:04:05:06 Using another destination port: $ wakeonlan -i 192.168.1.255 -p 1234 01:02:03:04:05:06 Using a file as source of hardware and IP addresses: $ wakeonlan -f examples/lab001.wol $ wakeonlan -f examples/lab001.wol 01:02:03:04:05:06 =head1 AUTHOR José Pedro Oliveira maintaining and expanding original work done by Ico Doornekamp . =head1 COPYRIGHT Copyright (c) 2000-2021 José Pedro Oliveira. This is free software. You may modify it and distribute it under Perl's Artistic License. Modified versions must be clearly indicated. =head1 SEE ALSO For more information regarding this script and Wakeonlan technology just check the project page at https://github.com/jpoliv/wakeonlan. =cut # vim:set ai ts=4 sw=4 sts=4 syntax=perl: