WOL Script (Wake on LAN)

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • so habe mir ein paar infos rausgesucht...es geht über ein sogenanntes "magic paket"...hmm..

    das Magic Paket hat folgenden aufbau:

    Magic Packet-Technologie

    Wake Up On LAN verwendete ursprünglich eine als Magic
    Packet bekannte Technik, die ein Datenpaket direkt an
    ein System sendet. Dieses Paket besteht aus Daten mit
    16-facher Wiederholung der Adresse des MAC-Layers. Die
    MAC-Adresse ist nur einmal für den Netzwerkadapter im
    System vorhanden, so daß das Magic Packet nur das für
    den Start ausgewählte System aktiviert. Wenn der
    Netzwerkadapter dieses Paket empfängt und
    entschlüsselt, sendet er ein PME-Signal an das
    System, wodurch es wieder vollständig aktiviert und
    gestartet wird.

    Interessant...jetzt nur noch die frage, wie ich so ein paket versende ...
    Lerne nicht Programmiersprachen, lerne Programmieren...

    :D Alles andere ist Syntax :D

    [Blockierte Grafik: http://www.xing.com/img/buttons/10_en_btn.gif]
  • mit welcher sprache willst du eigentlich coden?
    für linux gibts das programm "wakeonlan" - ist bei den meisten distris vorhanden

    ist ja GPL.. daher hier der code
    Usage
    wakeonlan [-h] [-v] [-i IP_address] [-p port] [-f file] [[hardware_address] ...]

    Options
    -h
    this information
    -v
    displays the script version
    -i ip_address
    set the destination IP address
    default: 255.255.255.255 (the limited broadcast address)
    -p port
    set the destination port
    default: 9 (the discard port)
    -f file
    uses file as a source of hardware addresses


    Quellcode

    1. #!/usr/bin/perl -w
    2. #
    3. # $Id: wakeonlan,v 1.4.2.3 2005/01/27 16:03:54 jpo Exp $
    4. #
    5. #########################################################################
    6. use strict;
    7. use Net::hostent;
    8. use Socket;
    9. use Getopt::Std;
    10. use vars qw($VERSION $opt_v $opt_h $opt_i $opt_p $opt_f);
    11. $VERSION = '0.41';
    12. my $DEFAULT_IP = '255.255.255.255';
    13. my $DEFAULT_PORT = getservbyname('discard', 'udp');
    14. #
    15. # Process the command line
    16. #
    17. getopts("hvp:i:f:");
    18. if ($opt_h) { usage(); exit(0); }
    19. if ($opt_v) { print "wakeonlan version $VERSION\n"; exit(0); }
    20. if (!$opt_f and !@ARGV) { usage(); exit(0); }
    21. if ($opt_i) { $DEFAULT_IP = $opt_i; } # override default value
    22. if ($opt_p) { $DEFAULT_PORT = $opt_p; } # override default value
    23. if ($opt_f) { process_file($opt_f); }
    24. # The rest of the command line is a list of hardware addresses
    25. foreach (@ARGV) {
    26. wake($_, $opt_i, $opt_p);
    27. }
    28. #
    29. # wake
    30. #
    31. # The 'magic packet' consists of 6 times 0xFF followed by 16 times
    32. # the hardware address of the NIC. This sequence can be encapsulated
    33. # in any kind of packet, in this case an UDP packet targeted at the
    34. # discard port (9).
    35. #
    36. sub wake
    37. {
    38. my $host = shift;
    39. my $ipaddr = shift || $DEFAULT_IP;
    40. my $port = shift || $DEFAULT_PORT;
    41. my ($raddr, $them, $proto);
    42. my ($hwaddr, $hwaddr_re, $pkt);
    43. # get the hardware address (ethernet address)
    44. $hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6);
    45. if ($host =~ m/^$hwaddr_re$/) {
    46. $hwaddr = $host;
    47. } else {
    48. # $host is not a hardware address, try to resolve it
    49. my $ip_re = join('\.', ('([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))') x 4);
    50. my $ip_addr;
    51. if ($host =~ m/^$ip_re$/) {
    52. $ip_addr = $host;
    53. } else {
    54. my $h;
    55. unless ($h = gethost($host)) {
    56. warn "$host is not a hardware address and I could not resolve it as to an IP address.\n";
    57. return undef;
    58. }
    59. $ip_addr = inet_ntoa($h->addr);
    60. }
    61. # look up ip in /etc/ethers
    62. unless (open (ETHERS, '<', '/etc/ethers')) {
    63. warn "$host is not a hardware address and I could not open /etc/ethers.\n";
    64. return undef;
    65. }
    66. while (<ETHERS>) {
    67. if (($_ !~ m/^$/) && ($_ !~ m/^#/)) { # ignore comments
    68. my ($mac, $ip);
    69. ($mac, $ip) = split(' ', $_, 3);
    70. if ($ip =~ m/^$ip$/) {
    71. if ($ip eq $ip_addr) {
    72. $hwaddr = $mac;
    73. last;
    74. }
    75. next;
    76. } else {
    77. my $h2;
    78. unless ($h2 = gethost($ip)) {
    79. next;
    80. }
    81. if (inet_ntoa($h2->addr) eq $ip_addr) {
    82. $hwaddr = $mac;
    83. last;
    84. }
    85. }
    86. }
    87. }
    88. close (ETHERS);
    89. unless (defined($hwaddr)) {
    90. warn "Could not find $host in /etc/ethers\n";
    91. return undef;
    92. }
    93. }
    94. # Generate magic sequence
    95. foreach (split /:/, $hwaddr) {
    96. $pkt .= chr(hex($_));
    97. }
    98. $pkt = chr(0xFF) x 6 . $pkt x 16;
    99. # Allocate socket and send packet
    100. $raddr = gethostbyname($ipaddr)->addr;
    101. $them = pack_sockaddr_in($port, $raddr);
    102. $proto = getprotobyname('udp');
    103. socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!";
    104. setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!";
    105. print "Sending magic packet to $ipaddr:$port with $hwaddr\n";
    106. send(S, $pkt, 0, $them) or die "send : $!";
    107. close S;
    108. }
    109. #
    110. # process_file
    111. #
    112. sub process_file {
    113. my $filename = shift;
    114. my ($hwaddr, $ipaddr, $port);
    115. open (F, "<$filename") or die "open : $!";
    116. while(<F>) {
    117. next if /^\s*#/; # ignore comments
    118. next if /^\s*$/; # ignore empty lines
    119. chomp;
    120. ($hwaddr, $ipaddr, $port) = split;
    121. wake($hwaddr, $ipaddr, $port);
    122. }
    123. close F;
    124. }
    Alles anzeigen
  • Ich benötige dies unter Windows für ein Netzwerkscript..

    ich möchte zb. folgendes aufrufen im Script:
    wake.exe -ip 192.168.115.7 -mac 0002A5F95974

    und dann sollte er mir den pc einschalten bzw. das signal senden...
    mal schauen, vieleicht kann ich mir ja aus denem script was basteln

    ich möchte dies in C++ Programmieren
    Lerne nicht Programmiersprachen, lerne Programmieren...

    :D Alles andere ist Syntax :D

    [Blockierte Grafik: http://www.xing.com/img/buttons/10_en_btn.gif]