Go: Socket Library to Get Hostname

Is there any equivalent to python socket library in Go?

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!

0

1 Answer

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest