Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function WakeOnLAN($mac_hex, $broadcastAddress) {
- $mac_hex2 = str_replace(':', '', $mac_hex);
- if (!ctype_xdigit($mac_hex2)) {
- echo timestamp();
- echo " <font color=\"red\">MAC Adresse ungültig, nur Ziffern von 0-9 und Buchstaben von a-f sind erlaubt!</font>";
- }
- else {
- $mac_bin = pack('H12', $mac_hex2);
- $magicPacket = str_repeat("\xff", 6) . str_repeat($mac_bin, 16);
- $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- if ($s == false) {
- echo timestamp();
- echo " <font color=\"red\">Fehler beim Erstellen des Sockets!";
- echo "<br>" . timestamp();
- echo " <br>Fehlercode: '".socket_last_error($s)."' - " . socket_strerror(socket_last_errpr($s)) . "</font>";
- }
- else {
- echo "<br>" . timestamp();
- echo " <font color=\"lime\">Socket erfolgreich erstellt";
- $opt_ret = socket_set_option($s, 1, 6, TRUE);
- if ($opt_ret < 0) {
- echo ".<br>" . timestamp();
- echo " <font color=\"red\">setsockopt() fehlgeschlagen, Error: " . strerror($opt_ret) . "</font></font>";
- }
- else {
- echo " und geöffnet.</font>";
- $e = socket_sendto($s, $magicPacket, strlen($magicPacket), 0, $broadcastAddress, 2050);
- echo "<br>" . timestamp();
- echo " Magic Packet an ".$broadcastAddress." mit der MAC=".$mac_hex." gesendet.";
- socket_close($s);
- echo "<br>" . timestamp();
- echo " Socket geschlossen.";
- }
- }
- }
- }
- function ping($ip) {
- $pingresult = exec("/bin/ping -c 1 $ip", $outcome, $status);
- if ($status == 0) {
- return true;
- }
- else {
- return false;
- }
- }
- function timestamp() {
- $datum = date("d.m.Y");
- $uhrzeit = date("H:i:s");
- return "<font color=\"blue\">[$datum - $uhrzeit]</font>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment