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
+18.6k Golang : Set, Get and List environment variables
+7.6k Golang : How to stop user from directly running an executable file?
+30.6k Golang : Remove characters from string example
+18.7k Golang : Find IP address from string
+18.8k Golang : Delete duplicate items from a slice/array
+19.2k Golang : Execute shell command
+19.2k Golang : Delete item from slice based on index/key position
+11.8k Golang : Verify Linux user password again before executing a program example
+5.5k Golang : Display advertisement images or strings on random order
+16.5k Golang : Execute terminal command to remote machine example
+5.2k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+16k Golang : Get file permission