Python:抓取任意URI的A记录?

发布于 2024-08-05 16:09:24 字数 493 浏览 4 评论 0原文

我基本上想实现一些可以输入任何 URI 的东西(我可能只会处理 http ),并且我想返回 URI 中域的 A 记录,我想要服务器的 IP 地址。

我知道大多数人使用 ping 命令来查找 IP 地址,但我也知道有更具体的“host”和“dig”。

我可以使用任何本机函数来为我执行此操作吗?如果是这样,该函数在它接受的 URI 字符串及其结构方面有多宽松?我想抛出它:

基本上任何东西都会返回 IP 地址。如果需要,我可以自己处理 URI 解析(因此在查找时它是一致的格式),但这是一个额外的优点。

I basically want to implement something where you can type in any URI ( I probably will only deal with http ) and I want to return the A record of the domain in the URI, I want the server's IP address.

I know there's the ping command which most people use to look an ip address up, but I also know there's 'host' and 'dig' which are more specific.

Are there any native functions I can use that will do this for me? And if so, how lenient is that function in terms of what URI string it accepts and the structure it's in? I want to throw it:

And have basically anything return an IP address. If need be I can take care of the URI parsing ( so it's a consistent format when looked up ) myself, that's an extra plus though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少钕鈤記 2024-08-12 16:09:24
py> import urlparse,socket
py> p = urlparse.urlparse("http://stackoverflow.com/questions/1480183")
py> p
('http', 'stackoverflow.com', '/questions/1480183', '', '', '')
py> host=p[1]
py> ai=socket.gethostbyname(host)
py> socket.gethostbyname(host)
'69.59.196.211'
py> import urlparse,socket
py> p = urlparse.urlparse("http://stackoverflow.com/questions/1480183")
py> p
('http', 'stackoverflow.com', '/questions/1480183', '', '', '')
py> host=p[1]
py> ai=socket.gethostbyname(host)
py> socket.gethostbyname(host)
'69.59.196.211'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文