Ubuntu上のドメイン名解析のテクニック

4014 ワード

1.目的
ubuntuでは、ドメイン名の解析を迅速に行いたい場合は、以下の方法で行うことができます.
2.ドメイン名解析を取得するプログラム
次のコードをmainとして保存します.cpp.
#include 
#include 
#include 
#include 

extern int h_errno;

int main(int argc, char **argv)
{
    if (argc != 2) {
        printf("Use example: %s www.google.com
"
, *argv); return -1; } char *name = argv[1]; struct hostent *hptr; hptr = gethostbyname(name); if (hptr == NULL) { printf("gethostbyname error for host: %s: %s
"
, name, hstrerror(h_errno)); return -1; } // printf("\tofficial: %s
"
, hptr->h_name); // char **pptr; char str[INET_ADDRSTRLEN]; for (pptr=hptr->h_aliases; *pptr!=NULL; pptr++) { printf("\ttalias: %s
"
, *pptr); } // ip switch (hptr->h_addrtype) { case AF_INET: pptr = hptr->h_addr_list; for (; *pptr!=NULL; pptr++) { printf("\taddress: %s
"
, inet_ntop(hptr->h_addrtype, hptr->h_addr, str, sizeof(str))); } break; default: printf("unknown address type
"
); break; } return 0; }

3.コンパイラ
gcc main.cpp

生成されたa.outファイルが表示されます
4.名前変更&&コピー&&権限変更
sudo cp a.out /usr/bin/dp
sudo chmod a+x /usr/bin/dp

5.ドメイン名解析の実行
dp www.baidu.com

戻る
official: www.a.shifen.com
talias: www.baidu.com
address: 180.97.33.108
address: 180.97.33.108