转到:套接字库获取主机名

Go中是否有等效于python套接字库的内容?
https://docs.python.org/2/library/socket.html </ p>

我想在Go中执行以下操作:</ p>

  import socket 
ip = socket.gethostbyname(domain +“ .multi.surbl.org”)
#翻译主机 名称转换为IPv4地址格式。
</ code> </ pre>

我可以在Go中使用什么软件包来做到这一点?</ p>

谢谢!</ p >
</ div>

展开原文

原文

Is there any equivalent to python socket library in Go? https://docs.python.org/2/library/socket.html

I want to do something like this in Go:

import socket
ip = socket.gethostbyname(domain + ".multi.surbl.org")
# Translate a host name to IPv4 address format.

What package can I use to do this in Go?

Thanks!

1个回答

展开原文

原文

The net namespace contains methods to translate hostnames to IP addresses (and a few other calls similar to what's in the Python socket namespace)

The call you're probably looking for is net.LookupHost or net.LookupIP;

addrs, err := net.LookupHost(hostname)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问