static protected String domainFromHost(String host){
  debugOut("domainFromHost(\"" + host + "\")");
  String domain=null;
  Matcher mat;
  mat=ipCapPattern.matcher(host);
  if (mat.find()) {
    domain=mat.group(5) + "." + mat.group(4)+ "."+ mat.group(3)+ "."+ mat.group(2);
    debugOut("domain=\"" + domain + "\"");
    return domain;
  }
  mat=tld3CapPattern.matcher(host);
  if (mat.find()) {
    String tld=mat.group(2);
    if (TLDLookup.isThreePartTLD(tld)) {
      domain=mat.group(1);
      debugOut("domain=\"" + domain + ", tld=\""+ tld+ "\"");
      return domain;
    }
  }
  mat=tld2CapPattern.matcher(host);
  if (mat.find()) {
    String tld=mat.group(2);
    if (TLDLookup.isTwoPartTLD(tld)) {
      domain=mat.group(1);
      debugOut("domain=\"" + domain + ", tld=\""+ tld+ "\"");
      return domain;
    }
  }
  mat=tldCapPattern.matcher(host);
  if (mat.find()) {
    String tld=mat.group(2);
    domain=mat.group(1);
    debugOut("domain=\"" + domain + ", tld=\""+ tld+ "\"");
    return domain;
  }
  return domain;
}

static protected String domainFromHost ( String host ) { debugOut ( "domainFromHost(\"" + host + "\")" ) ; String domain = null ; Matcher mat ; mat = ipCapPattern . matcher ( host ) ; if ( mat . find ( ) ) { domain = mat . group ( 5 ) + "." + mat . group ( 4 ) + "." + mat . group ( 3 ) + "." + mat . group ( 2 ) ; debugOut ( "domain=\"" + domain + "\"" ) ; return domain ; } mat = tld3CapPattern . matcher ( host ) ; if ( mat . find ( ) ) { String tld = mat . group ( 2 ) ; if ( TLDLookup . isThreePartTLD ( tld ) ) { domain = mat . group ( 1 ) ; debugOut ( "domain=\"" + domain + ", tld=\"" + tld + "\"" ) ; return domain ; } } mat = tld2CapPattern . matcher ( host ) ; if ( mat . find ( ) ) { String tld = mat . group ( 2 ) ; if ( TLDLookup . isTwoPartTLD ( tld ) ) { domain = mat . group ( 1 ) ; debugOut ( "domain=\"" + domain + ", tld=\"" + tld + "\"" ) ; return domain ; } } mat = tldCapPattern . matcher ( host ) ; if ( mat . find ( ) ) { String tld = mat . group ( 2 ) ; domain = mat . group ( 1 ) ; debugOut ( "domain=\"" + domain + ", tld=\"" + tld + "\"" ) ; return domain ; } return domain ; }
extracts and returns the registrar domain portion of a host string . this funtion checks all known multi - part tlds to make sure that registrar domain is complete . for example , if the supplied host string is " subdomain . example . co . uk " , the tld is " co . uk " and not " uk " . therefore , the correct registrar domain is not " co . uk " , but " example . co . uk " . if the domain string is an ip address , then the octets are returned in reverse order .
