C/C ++中的DNS解析 [英] DNS resolving in C/C++

查看:80
本文介绍了C/C ++中的DNS解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,我可以像这样使用DNS:

In python I can work with DNS like this:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns.resolver
>>> answer = dns.resolver.query('www.example.com')
>>> print answer.response
id 37102
opcode QUERY
rcode NOERROR
flags QR RD RA
;QUESTION
www.example.com. IN A
;ANSWER
www.example.com. 3600 IN A 93.184.216.34
;AUTHORITY
;ADDITIONAL
>>> print answer.rrset
www.example.com. 3600 IN A 93.184.216.34
>>>

在C/C ++中获得相同结果的最简单方法是什么?使用库(哪个是最流行的?)或通过套接字或其他方式手动发送请求.

What's the easiest way to achieve the same result in C/C++? Either using a library (which one most popular?) or sending the request manuall via sockets or something.

推荐答案

getaddrinfo .然后 res_ *函数用于高级查询.这些其他功能也可能对您有用.

Start with getaddrinfo. Then the res_* functions for advanced queries. These other functions might be useful to you as well.

gethostbyname

getnameinfo

gethostent

这篇关于C/C ++中的DNS解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆