{"id":3934,"date":"2025-02-12T02:38:39","date_gmt":"2025-02-11T17:38:39","guid":{"rendered":"https:\/\/www.lastspiral.com\/?p=3934"},"modified":"2025-02-12T02:46:55","modified_gmt":"2025-02-11T17:46:55","slug":"python%e3%81%a7%e3%83%8d%e3%83%83%e3%83%88%e3%83%af%e3%83%bc%e3%82%af%e4%b8%8a%e3%81%aepc%e3%82%92%e8%b5%b7%e5%8b%95%e3%81%99%e3%82%8b-wol-wake-on-lan","status":"publish","type":"post","link":"https:\/\/www.lastspiral.com\/?p=3934","title":{"rendered":"Python\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u4e0a\u306ePC\u3092\u8d77\u52d5\u3059\u308b WOL Wake On Lan"},"content":{"rendered":"\n<p>\u305f\u3063\u305f11\u884c\u306e\u30b3\u30fc\u30c9\u3067\u3067\u304d\u308b\u3093\u3060\u306d\u3002\u899a\u66f8\u3068\u3057\u3066\u8a18\u9332\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<p>\u8d77\u52d5\u3057\u305f\u3044 PC \u306e MAC \u30a2\u30c9\u30ec\u30b9\u3092\u6307\u5b9a(mac_address ) \u3057\u3066\u4fdd\u5b58\u5f8c\u3001\u5b9f\u884c\u3059\u308b\u3060\u3051\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#c0c0c052\"><code>import socket\nimport struct\n\ndef send_wol_packet(mac_address):\n  # MAC \u30a2\u30c9\u30ec\u30b9\u3092\u30d0\u30a4\u30c8\u914d\u5217\u306b\u5909\u63db\n  mac_address = mac_address.replace(':', '')\n  mac_address_bytes = bytes.fromhex(mac_address)\n\n  # \u30de\u30b8\u30c3\u30af\u30d1\u30b1\u30c3\u30c8\u3092\u4f5c\u6210\n  magic_packet = b'\\xff' * 6 + mac_address_bytes * 16\n\n  # UDP \u30d1\u30b1\u30c3\u30c8\u3092\u9001\u4fe1\n  with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:\n    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)\n    s.sendto(magic_packet, ('192.168.1.255', 9)) # '192.168.1.255'\u306f\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u7f6e\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\n\n# \u8d77\u52d5\u3057\u305f\u3044 PC \u306e MAC \u30a2\u30c9\u30ec\u30b9\u3092\u6307\u5b9a\nmac_address = \"XX:XX:XX:XX:XX:XX\" # \u5b9f\u969b\u306eMAC\u30a2\u30c9\u30ec\u30b9\u306b\u7f6e\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\n\n# WOL \u30d1\u30b1\u30c3\u30c8\u3092\u9001\u4fe1\nsend_wol_packet(mac_address)<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u305f\u3063\u305f11\u884c\u306e\u30b3\u30fc\u30c9\u3067\u3067\u304d\u308b\u3093\u3060\u306d\u3002\u899a\u66f8\u3068\u3057\u3066\u8a18\u9332\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3934","post","type-post","status-publish","format-standard","hentry","category-pc"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=\/wp\/v2\/posts\/3934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3934"}],"version-history":[{"count":4,"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=\/wp\/v2\/posts\/3934\/revisions"}],"predecessor-version":[{"id":3939,"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=\/wp\/v2\/posts\/3934\/revisions\/3939"}],"wp:attachment":[{"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lastspiral.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}