title: How to verify if DB remote server is running using only java raw sockets [Telnet]
body: <p>I wanted to explore an option to write minimal code to check if db2 server is running using plain java sockets. Just like doing telnet to server. It seems db2 is not configured to respond for telnet connection. Any help?
  Below code works for mysql, but not working db2.</p>
  
  <blockquote>
    <p>This code is equivalent to telnet ip port</p>
  </blockquote>
  
  <pre><code>Below is the java code
  
      import java.io.IOException;
      import java.io.InputStream;
      import java.net.Socket;
      import java.util.regex.Matcher;
      import java.util.regex.Pattern;
      public class myApp {
          public static void main(String[] args) throws IOException {
              Socket socket = new Socket("192.168.8.142", 50000);
              String pattern = "mysql|oracle|db2";
              Pattern r = Pattern.compile(pattern);
              InputStream in = socket.getInputStream();
              byte[] b = new byte[512];
              in.read(b);
              String response = new String(b);
              in.close();
              socket.close();
              Matcher m = r.matcher(response);
              System.out.println(m.find(0));
          }
      }
  </code></pre>
  
  <blockquote>
    <p>For mysql2, telnet return some characters with mysql text, version and some encoded ascii characters. But for db2, its seems like telnet is stuck without any response.</p>
  </blockquote>