Java tutorial
//package com.java2s; //License from project: Apache License import java.net.*; public class Main { static boolean resolve_dns = false; public static String shortName(String hostname) { if (hostname == null) return null; int index = hostname.indexOf('.'); if (index > 0 && !Character.isDigit(hostname.charAt(0))) return hostname.substring(0, index); else return hostname; } public static String shortName(InetAddress hostname) { if (hostname == null) return null; StringBuilder sb = new StringBuilder(); if (resolve_dns) sb.append(hostname.getHostName()); else sb.append(hostname.getHostAddress()); return sb.toString(); } }