差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン | |||
| python:socket:programming [2020/09/11 19:23] – ともやん | python:socket:programming [2021/06/25 15:48] (現在) – ともやん | ||
|---|---|---|---|
| 行 13: | 行 13: | ||
| from traceback import print_exc | from traceback import print_exc | ||
| - | DEFAULT_PORT = 7 | + | DEFAULT_PORT = 7 # 7 or 9 or 30000 ? |
| + | # | ||
| + | BROADCAST_IPADDR = ' | ||
| def send_magic_packet(mac_addr, | def send_magic_packet(mac_addr, | ||
| 行 20: | 行 22: | ||
| sock.setsockopt(socket.SOL_SOCKET, | sock.setsockopt(socket.SOL_SOCKET, | ||
| # parse address | # parse address | ||
| - | | + | |
| - | wol_mac = mac_addr.replace(' | + | |
| if len(wol_mac) != 12: | if len(wol_mac) != 12: | ||
| - | raise Exception(' | + | raise Exception(' |
| buf = b' | buf = b' | ||
| # encode to magic packet payload | # encode to magic packet payload | ||
| 行 32: | 行 33: | ||
| # send magic packet | # send magic packet | ||
| print(' | print(' | ||
| - | sock.sendto(magic_packet, | + | sock.sendto(magic_packet, |
| def parse_args(): | def parse_args(): | ||
| parser = argparse.ArgumentParser() | parser = argparse.ArgumentParser() | ||
| parser.add_argument(' | parser.add_argument(' | ||
| - | parser.add_argument(' | + | parser.add_argument(' |
| help=' | help=' | ||
| default=DEFAULT_PORT, | default=DEFAULT_PORT, | ||
| 行 48: | 行 49: | ||
| try: | try: | ||
| + | #mac_addr = " | ||
| send_magic_packet(mac_addr, | send_magic_packet(mac_addr, | ||