IP2WHOIS #Domain-WHOIS-API: ドメイン情報を取得

IP2WHOIS #Domain-WHOIS-API: ドメイン情報を取得

translate IP2WHOIS #Domain-WHOIS-API: Obtain Domain-Info

ドメイン形式文字列(サブドメインを含む)から “登録済みドメイン名” および “ドメインの日齢” (WHOISレコード)を取得します。登録されていない場合、エラーとなります。無料APIライセンスは、1か月あたり最大500クエリに制限されます。

Auto Step icon
Configs for this Auto Step
AuthzConfU
U: API LICENSE KEY が格納されているHTTP認証設定を選択してください(トークン直接指定) *
StrConfA
A: ドメインをセットしてください (eg: `example.com`, `https://sub.example.jp`) *#{EL}
SelectConfB1
B1: 登録済みドメイン名が格納される文字列型データを選択してください (更新)
SelectConfB2
B2: ドメイン名の日齢が格納される数値型データを選択してください (更新)
SelectConfX
X: レスポンス JSON が格納される文字列型データを選択してください (更新)
Script (click to open)
// Script Example of Business Process Automation
// for 'engine type: 3' ("GraalJS standard mode")
// cf. 'engine type: 2' ("GraalJS Nashorn compatible mode") (renamed from "GraalJS" at 20230526)

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

////// == Config Retrieving / 工程コンフィグの参照 ==
const authApiKey                = configs.getObject( "AuthzConfU" );     /// REQUIRED
const strApiKey                 = authApiKey.getToken();
//  engine.log( " AutomatedTask Config: ApiKey: " + strApiKey );

const strDomainName             = configs.get      ( "StrConfA" );       /// REQUIRED
  if( strDomainName === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A: DomainName} is empty \n" );
  }
  let strDomainExtracted        = extractLooseDomain( strDomainName );
  if (strDomainExtracted === null) {
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Could not extract domain from Config {A: DomainName} \n");
  }
const strPocketRegisteredDomain = configs.getObject( "SelectConfB1" );   // not required
const numPocketAgeInDays        = configs.getObject( "SelectConfB2" );   // not required
const strPocketResponseJson     = configs.getObject( "SelectConfX" );    // not required



////// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)



////// == Calculating / 演算 ==

//// Domain WHOIS REST API > WHOIS lookup REST API
//// https://www.ip2whois.com/developers-api
//// https://www.ip2location.io/ip2whois-documentation

/// request1, prepare
let request1Uri = "https://api.ip2whois.com/v2";
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.queryParam( "key", strApiKey ); 
    request1 = request1.queryParam( "domain", strDomainExtracted ); 

/// request1, try
const response1     = request1.get( request1Uri );     // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + "";  // JavaNum to string
const response1Body = response1.getResponseAsString();
engine.log( " AutomatedTask ApiResponse1 Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
// engine.log( response1Body ); // debug
/* response sample
{
  "domain": "google.com",
  "domain_id": "2138514_DOMAIN_COM-VRSN",
  "status": "clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)",
  "create_date": "1997-09-15T07:00:00+0000",
  "update_date": "2024-08-02T02:17:33+0000",
  "expire_date": "2028-09-13T07:00:00+0000",
  "domain_age": 10179,
  "whois_server": "whois.markmonitor.com",
  "registrar": { ... },
  "registrant": { ... },
  "admin": { ... },
  "tech": { ... },
  "billing": { ... },
  "nameservers: [
    "ns4.google.com",
    "ns1.google.com",
    "ns2.google.com",
    "ns3.google.com"
  ]
}
*/

// response1, parse
const response1Obj = JSON.parse( response1Body );


////// == Data Updating / ワークフローデータへの代入 ==
if( strPocketRegisteredDomain !== null ){
  engine.setData( strPocketRegisteredDomain, response1Obj.domain  );
}
if( numPocketAgeInDays !== null ){
  engine.setData( numPocketAgeInDays, new java.math.BigDecimal(response1Obj.domain_age)  );
}
if( strPocketResponseJson !== null ){
  engine.setData( strPocketResponseJson, response1Body  );
}


} //////// END "main()" /////////////////////////////////////////////////////////////////


/**
 * 与えられたテキストから、最初のドメイン文字列(サブドメインを含むドメインらしき文字列)を抽出します。
 *
 * @param {string} text - ドメインを抽出したい元の文字列。
 * @returns {string|null} - 見つかった最初のドメイン文字列。マッチしない場合は null を返します。
 *
 * @example
 * // 基本的なドメインの抽出
 * extractLooseDomain("私のウェブサイトは example.com です。"); // 'example.com' を返します
 *
 * @example
 * // サブドメインを含むドメインの抽出
 * extractLooseDomain("連絡先は info@sub.domain.co.jp です。"); // 'sub.domain.co.jp' を返します
 *
 * @example
 * // URLの一部として含まれるドメインの抽出
 * extractLooseDomain("URLは https://www.google.com/search?q=test です。"); // 'www.google.com' を返します
 *
 * @example
 * // Punycode 形式のドメインの抽出
 * extractLooseDomain("Punycodeドメイン: xn--abc-xyz.jp です。"); // 'xn--abc-xyz.jp' を返します
 *
 * @example
 * // ドメインが見つからない場合
 * extractLooseDomain("ドメインのない文章です。"); // null を返します
 */
function extractLooseDomain(text) {
  // まず、メールアドレスっぽい文字列を検出
  const emailMatch = text.match(/[a-zA-Z0-9._%+-]+@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/);
  if (emailMatch) {
    return emailMatch[1]; // @の右側のドメイン部を返す
  }

  // サブドメインを含む "ドメインらしき文字列" を抽出する正規表現。
  // TLDの長さ、ハイフン、数字、Punycode形式に対応し、大文字小文字を区別しません。
  const domainRegex = /(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+(?:[a-zA-Z]{2,20}|xn--[a-zA-Z0-9]{1,61})(?:\.[a-zA-Z]{2})?/i;
  
  const match = text.match(domainRegex);

  if (match) {
    return match[0]; // マッチした文字列全体(ドメイン部分)を返します
  }

  return null; // マッチしない場合は null を返します
}




/*
Notes:
- If place this [Automated Atep] in the workflow diagram, the API request will occur every time a process arrives.
    - Requests from the Questetra BPM Suite server to the IP2WHOIS server.
- This [Automated Step] obtains the Domain Information via IP2WHOIS API.
    - Registered domain name (officially registered and available for use)
    - Number of days since the domain was created
    - The full JSON response can be stored as a string.
- [HTTP Authz Settings] is required for workflow apps that include this [Automated Step].
    - An API key is required to use IP2WHOIS API. Please obtain an API key in advance.
        - `https://www.ip2location.io/dashboard`
    - Set 'Secret API Key' as communication token. [HTTP Authz Settings] > [Token Fixed Value]

APPENDIX
- The query for 1221 TLDs and 634 ccTLDs are supported. (by IP2WHOIS as of 202507)
- Matches domain names in the format 'example.com' or 'subdomain.example.co.jp'.
    - output: `example.com`
    - output: `subdomain.example.co.jp`
- Extracts the registered domain portion even from strings like 'http://example.com/.' or 'suzuki@subdomain.example.co.jp'.
    - output: `example.com`
    - output: `subdomain.example.co.jp`

Notes-ja:
- この[自動工程]をワークフロー図に配置すれば、案件が到達するたびにAPIリクエストが発生します。
    - Questetra BPM Suite サーバから IP2WHOIS サーバに対してリクエストします。
- この[自動工程]は、IP2WHOIS API を通じて、ドメイン情報を取得します。
    - 登録済みドメイン名(正式に登録され利用可能な状態になっているドメイン)
    - ドメインが生成されてからの日数
    - JSON response の全文も格納可能です。
- この[自動工程]を含むワークフローアプリには、[HTTP 認証設定]が必要です。
    - IP2WHOIS API の利用には API key が必要です。あらかじめ API Key を取得しておいてください。
        - `https://www.ip2location.io/dashboard`
    - 'Secret API Key' を通信トークンとしてセットします。[HTTP 認証設定]>[トークン直接指定]

APPENDIX-ja
- 1221のTLDと634のccTLDのクエリをサポートしています。 (by IP2WHOIS as of 202507)
- 'example.com' や 'subdomain.example.co.jp' のような形式のドメイン名にマッチします。
    - output: `example.com`
    - output: `subdomain.example.co.jp`
- 'http://example.com/.' や 'suzuki@subdomain.example.co.jp' のような文字列でも登録ドメイン部を抽出します。
    - output: `example.com`
    - output: `subdomain.example.co.jp`
*/

Download

warning 自由改変可能な JavaScript (ECMAScript) コードです。いかなる保証もありません。
(アドオン自動工程のインストールは Professional editionでのみ可能です)

Notes

  • この[自動工程]をワークフロー図に配置すれば、案件が到達するたびにAPIリクエストが発生します。
    • Questetra BPM Suite サーバから IP2WHOIS サーバに対してリクエストします。
  • この[自動工程]は、IP2WHOIS API を通じて、ドメイン情報を取得します。
    • 登録済みドメイン名(正式に登録され利用可能な状態になっているドメイン)
    • ドメインが生成されてからの日数
    • JSON response の全文も格納可能です。
  • この[自動工程]を含むワークフローアプリには、[HTTP 認証設定]が必要です。
    • IP2WHOIS API の利用には API key が必要です。あらかじめ API Key を取得しておいてください。
      • https://www.ip2location.io/dashboard
    • ‘Secret API Key’ を通信トークンとしてセットします。[HTTP 認証設定]>[トークン直接指定]

Capture

Appendix

  • 1221のTLDと634のccTLDのクエリをサポートしています。 (by IP2WHOIS as of 202507)
  • example.comsubdomain.example.co.jp のような形式のドメイン名にマッチします。
    • output: example.com
  • http://example.com/.suzuki@subdomain.example.co.jp でも登録ドメイン名を抽出します。
    • output: example.com

See Also

上部へスクロール

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む