Skip to content

More flexible defaults #19

@monnier

Description

@monnier

For me the main missing convenience (beside issue #12) is the ability to change the default target IP (I often use wakeonlan from my home router where I want to send the packet to the local "lan" network and not to the "wan" side).

I use the following patch for now, which adds two features:

  • Read ~/.wakeonlan when it exists (and when -f was not specified).
  • Allow the special * hwaddr in those files to mean that the specified IP (and port) is to be used by default.
diff --git a/wakeonlan b/wakeonlan                                              
index 1d85f93..b7c8475 100755                                                   
--- a/wakeonlan                                                                 
+++ b/wakeonlan                                                                 
@@ -121,12 +121,6 @@ sub loadFromFile {                                         
                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";                   
@@ -141,6 +135,17 @@ sub loadFromFile {                                         
                        next;                                                   
                }                                                               
                                                                                
+               if ($hwaddr eq "*") {                                          
+                       warn "Using default IP $ipaddr";                        
+                       $DEFAULT_IP = $ipaddr;                                  
+                       $DEFAULT_PORT = $port;                                  
+                       next;                                                   
+               } elsif (! isValidHardwareAddress($hwaddr) ) {                  
+                       warn "Invalid hardware address: $hwaddr\n";             
+                       $stats{invalid}++;                                      
+                       next;                                                   
+               }                                                               
+                                                                               
                $stats{valid}++;                                                
                push @queue, [ $hwaddr, $ipaddr, $port ];                       
        }                                                                       
@@ -262,6 +267,8 @@ if (!$filename and !@ARGV) { pod2usage( -exitval => 0, -ver\
bose => 1); };                                                                  
 #                                                                              
                                                                                
 loadFromCommandLine(@ARGV);                                                    
+                                                                               
+$filename = "$ENV{HOME}/.wakeonlan" if (!$filename && -e "$ENV{HOME}/.wakeonla\
n");                                                                            
 loadFromFile($filename) if $filename;                                          
                                                                                
 # print Dumper(@queue);                                                        

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions