code: def scan(host, port=80, url=None, https=False, timeout=1, max_size=65535):
      starts = OrderedDict()
      ends = OrderedDict()
      port = int(port)
      result = dict(
          host=host, port=port, state='closed', durations=OrderedDict()
      )
      if url:
          timeout = 1
          result['code'] = None
      starts['all'] = starts['dns'] = datetime.datetime.now()
      try:
          hostip = socket.gethostbyname(host)
          result['ip'] = hostip
          ends['dns'] = datetime.datetime.now()
      except socket.gaierror:
          raise ScanFailed('DNS Lookup failed', result=result)
      starts['connect'] = datetime.datetime.now()
      network_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      network_socket.settimeout(timeout)
      result_connection = network_socket.connect_ex((hostip, port))
      ends['connect'] = datetime.datetime.now()
      if https:
          starts['ssl'] = datetime.datetime.now()
          try:
              network_socket = ssl.wrap_socket(network_socket)
          except socket.timeout:
              raise ScanFailed('SSL socket timeout', result=result)
          ends['ssl'] = datetime.datetime.now()
      if result_connection == 0 and url:
          starts['request'] = datetime.datetime.now()
          network_socket.send(
              "GET {0} HTTP/1.0\r\nHost: {1}\r\n\r\n".format(
                  url, host
              ).encode('ascii'))
          if max_size:
              data = network_socket.recv(max_size)
          else:
              data = network_socket.recv()
          result['length'] = len(data)
          data = data.decode('ascii', errors='ignore')
          result['response'] = (data)
          try:
              result['code'] = int(data.split('\n')[0].split()[1])
          except IndexError:
              pass
          ends['request'] = datetime.datetime.now()
      network_socket.close()
      ends['all'] = datetime.datetime.now()
      for duration in starts.keys():
          if duration in ends.keys():
              result['durations'][duration] = ends[duration] - starts[duration]
      if result_connection == 0:
          result['state'] = 'open'
      return result