old_contents: import logging
  
  def execute(remote, command):
      chan, stdin, stderr, stdout = execute_async(remote, command)
      result = {
          'stdout': [],
          'stderr': [],
          'exit_code': 0
      }
      for line in stdout:
          result['stdout'].append(line)
          print line
      for line in stderr:
          result['stderr'].append(line)
          print line
  
      result['exit_code'] = chan.recv_exit_status()
      chan.close()
  
      return result
  
  def udp_ping(remote, host, port):
      result = execute(remote,'nmap -PU -sU -p%s %s' % (host, port))
      for line in result['stdout']:
          if line.find('udp open'):
              return True
      return False
  
  def udp_ping(remote, host, port):
      result = execute(remote,'nmap -PU -sU -p%s %s' % (host, port))
      for line in result['stdout']:
          if line.find('udp open'):
              return True
      return False
  
  def execute_async(remote, command):
      logging.debug("Executing command: '%s'" % command.rstrip())
      chan = remote._ssh.get_transport().open_session()
      stdin = chan.makefile('wb')
      stdout = chan.makefile('rb')
      stderr = chan.makefile_stderr('rb')
      cmd = "%s\n" % command
      if remote.sudo_mode:
          cmd = 'sudo -S bash -c "%s"' % cmd.replace('"', '\\"')
      chan.exec_command(cmd)
      if stdout.channel.closed is False:
          stdin.write('%s\n' % remote.password)
          stdin.flush()
      return chan, stdin, stderr, stdout
  
  
new_contents: import logging
  
  def execute(remote, command):
      chan, stdin, stderr, stdout = execute_async(remote, command)
      result = {
          'stdout': [],
          'stderr': [],
          'exit_code': 0
      }
      for line in stdout:
          result['stdout'].append(line)
          print line
      for line in stderr:
          result['stderr'].append(line)
          print line
  
      result['exit_code'] = chan.recv_exit_status()
      chan.close()
  
      return result
  
  def udp_ping(remote, host, port):
      result = execute(remote,'nmap -PU -sU -p%s %s' % (host, port))
      for line in result['stdout']:
          if line.find('udp open'):
              return True
      return False
  
  def udp_ping(remote, host, port):
      result = execute(remote,'nmap -PU -sU -p%s %s' % (port, host))
      for line in result['stdout']:
          if line.find('udp open'):
              return True
      return False
  
  def tcp_ping(remote, host, port):
      result = execute(remote,'nmap -PU -p%s %s' % (port, host))
      for line in result['stdout']:
          if line.find('tcp open'):
              return True
      return False
  
  def execute_async(remote, command):
      logging.debug("Executing command: '%s'" % command.rstrip())
      chan = remote._ssh.get_transport().open_session()
      stdin = chan.makefile('wb')
      stdout = chan.makefile('rb')
      stderr = chan.makefile_stderr('rb')
      cmd = "%s\n" % command
      if remote.sudo_mode:
          cmd = 'sudo -S bash -c "%s"' % cmd.replace('"', '\\"')
      chan.exec_command(cmd)
      if stdout.channel.closed is False:
          stdin.write('%s\n' % remote.password)
          stdin.flush()
      return chan, stdin, stderr, stdout
  
  
subject: Add tcp ping with nmap