I need to get the result of dns resolution of the input URL using PyCurl. Following is the code:
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEFUNCTION, buf.write)
c.setopt(c, c.CURL_IPRESOLVE_WHATEVER, host)
c.setopt(c.HTTPHEADER, ["User-Agent: "])
# c.setopt(c.CONNECTTIMEOUT, 20)
c.setopt(c.TIMEOUT, 15)
c.setopt(c.FOLLOWLOCATION, True)
c.perform()
I have searched the Pycurl Documentation and didn't find a good answer.
答案 0 :(得分:0)
我在Libcurl的文档中搜索并找到了此链接中描述的getinfo()
函数:https://curl.haxx.se/libcurl/c/curl_easy_getinfo.html
但要小心这是C和在Pycurl中使用它时,你必须使用此链接转换常量:
https://github.com/pycurl/pycurl/blob/master/src/module.c#L1134
作为检索后续网址的IP地址的答案应该添加:
print(c.getinfo(c.PRIMARY_IP))