Golang : Get IP addresses of a domain name
This small program demonstrate how to Golang's net.LookupIP() function to get the IP addresses from a given domain name.
package main
import (
"fmt"
"net"
"os"
)
func main(){
ip, _ := net.LookupIP(os.Args[1]) // take from 1st argument
fmt.Println(ip)
}
Output :
go run getipaddress.go google.com
[173.194.126.37 173.194.126.34 173.194.126.40 173.194.126.32 173.194.126.36 173.194.126.41 173.194.126.33 173.194.126.38 173.194.126.46 173.194.126.35 173.194.126.39 2404:6800:4001:801::1008]
Reference :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.5k Javascript : Generate random key with specific length
+21.3k Golang : Get password from console input without echo or masked
+7.7k Golang : How to stop user from directly running an executable file?
+21.9k Golang : Encrypt and decrypt data with TripleDES
+13.2k Golang : List objects in AWS S3 bucket
+11.4k Golang : Fix go.exe is not compatible with the version of Windows you're running
+6.5k Golang : How to get capacity of a slice or array?
+25.9k Golang : Generate MD5 checksum of a file
+11.6k Golang : Change date format to yyyy-mm-dd
+5.3k Golang : Issue HTTP commands to server and port example
+9.6k Golang : How to protect your source code from client, hosting company or hacker?
+7.6k Golang : Gorrila set route name and get the current route name