old_contents: import sys, socket, select, time
  from optparse import OptionParser
  
  XBOX_PORT = 5050
  XBOX_PING = "dd00000a000000000000000400000002"
  XBOX_POWER = "dd02001300000010"
  
  py3 = sys.version_info[0] > 2
  
  
  def main():
      parser = OptionParser()
      parser.add_option('-a', '--address', dest='ip_addr', help="IP Address of Xbox One", default='')
      parser.add_option('-i', '--id', dest='live_id', help="Live ID of Xbox One", default='')
      (opts, args) = parser.parse_args()
          
      if not opts.ip_addr:
          opts.ip_addr = user_input("Enter the IP address: ")
  
      if not opts.live_id:
          opts.live_id = user_input("Enter the Live ID: ")
  
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.setblocking(0)
      s.bind(("", 0))
      s.connect((opts.ip_addr, XBOX_PORT))
  
      if isinstance(opts.live_id, str):
          live_id = opts.live_id.encode()
      else:
          live_id = opts.live_id
  
      power_packet = bytearray.fromhex(XBOX_POWER) + live_id + b'\x00'
      print("Sending power on packets to {0}...".format(opts.ip_addr))
      send_power(s, power_packet)
  
      print("Xbox should turn on now, pinging to make sure...")
      ping_result = send_ping(s)
  
      if ping_result:
          print("Ping successful!")
      else:
          print("Failed to ping Xbox :( - do you wish to keep trying?")
          result = ""
          while result not in ("y", "n"):
              result = user_input("(y/n): ").lower()
          if result == "y":
              print("Sending power packets and pinging until Xbox is on...")
              while not ping_result:
                  send_power(s, power_packet)
                  ping_result = send_ping(s)
              print("Ping successful!")
  
      s.close()
  
  
  def send_power(s, data, times=5):
      for i in range(0, times):
          s.send(data)
          time.sleep(1)
  
  
  def send_ping(s):
      s.send(bytearray.fromhex(XBOX_PING))
      return select.select([s], [], [], 5)[0]
  
  
  def user_input(text):
      response = ""
  
      while response == "":
          if py3:
              response = input(text)
          else:
              response = raw_input(text)
  
      return response
  
  if __name__ == "__main__":
      main()
  
new_contents: import sys, socket, select, time
  from argparse import ArgumentParser
  
  XBOX_PORT = 5050
  XBOX_PING = "dd00000a000000000000000400000002"
  XBOX_POWER = "dd02001300000010"
  
  py3 = sys.version_info[0] > 2
  
  
  def main():
      parser = ArgumentParser(description="Send power on packets to a Xbox One.")
      parser.add_argument('-a', '--address', dest='ip_addr', help="IP Address of Xbox One", default='')
      parser.add_argument('-i', '--id', dest='live_id', help="Live ID of Xbox One", default='')
      parser.add_argument('-f', dest='forever', help="Send packets until Xbox is on", action='store_true')
      args = parser.parse_args()
          
      if not args.ip_addr:
          args.ip_addr = user_input("Enter the IP address: ")
  
      if not args.live_id:
          args.live_id = user_input("Enter the Live ID: ")
  
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.setblocking(0)
      s.bind(("", 0))
      s.connect((args.ip_addr, XBOX_PORT))
  
      if isinstance(args.live_id, str):
          live_id = args.live_id.encode()
      else:
          live_id = args.live_id
  
      power_packet = bytearray.fromhex(XBOX_POWER) + live_id + b'\x00'
      print("Sending power on packets to {0}...".format(args.ip_addr))
      send_power(s, power_packet)
  
      print("Xbox should turn on now, pinging to make sure...")
      ping_result = send_ping(s)
  
      if ping_result:
          print("Ping successful!")
      else:
          print("Failed to ping Xbox :(")
          result = ""
          if not args.forever:
              while result not in ("y", "n"):
                  result = user_input("Do you wish to keep trying? (y/n): ").lower()
          if args.forever or result == "y":
              print("Sending power packets and pinging until Xbox is on...")
              while not ping_result:
                  send_power(s, power_packet)
                  ping_result = send_ping(s)
              print("Ping successful!")
  
      s.close()
  
  
  def send_power(s, data, times=5):
      for i in range(0, times):
          s.send(data)
          time.sleep(1)
  
  
  def send_ping(s):
      s.send(bytearray.fromhex(XBOX_PING))
      return select.select([s], [], [], 5)[0]
  
  
  def user_input(text):
      response = ""
  
      while response == "":
          if py3:
              response = input(text)
          else:
              response = raw_input(text)
  
      return response
  
  if __name__ == "__main__":
      main()
  
subject: Switch to argparse, add argument to keep sending packets