ubuntu域名解析怎么使用

这篇“ubuntu域名解析怎么使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“ubuntu域名解析怎么使用”文章吧。

1.获取域名解析的程序,将以下代码保存为“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\n", *argv);

return -1;

}


char *name = argv[1];

struct hostent *hptr;


hptr = gethostbyname(name);

if (hptr == NULL) {

printf("gethostbyname error for host: %s: %s\n", name, hstrerror(h_errno));

return -1;

}

//输出主机的规范名

printf("\tofficial: %s\n", hptr->h_name);


//输出主机的别名

char **pptr;

char str[INET_ADDRSTRLEN];

for (pptr=hptr->h_aliases; *pptr!=NULL; pptr++) {

printf("\ttalias: %s\n", *pptr);

}


//输出ip地址

switch (hptr->h_addrtype) {

case AF_INET:

pptr = hptr->h_addr_list;

for (; *pptr!=NULL; pptr++) {

printf("\taddress: %s\n",

inet_ntop(hptr->h_addrtype, hptr->h_addr, str, sizeof(str)));

}

break;

default:

printf("unknown address type\n");

break;

}


return 0;

}


2.编译程序,命令:

gcc main.cpp //会生成a.out文件


3.重命名&&拷贝&&权限修改,命令:

sudo cp a.out /usr/bin/dp

sudo chmod a+x /usr/bin/dp


4..执行域名解析,例如:

dp www.baidu.com


5.返回结果如下:

official: www.a.shifen.com

talias: www.baidu.com

address: 180.97.33.108

address: 180.97.33.108


以上就是关于“ubuntu域名解析怎么使用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注蜗牛博客行业资讯频道。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接