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
+9.1k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+7.2k Golang : Check to see if *File is a file or directory
+4.7k Python : Find out the variable type and determine the type with simple test
+16.5k Golang : Set up source IP address before making HTTP request
+11k Use systeminfo to find out installed Windows Hotfix(s) or updates
+35.6k Golang : Save image to PNG, JPEG or GIF format.
+12.3k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+9.5k Golang : interface - when and where to use examples
+9.8k CodeIgniter : Load different view for mobile devices
+23.4k Golang : Fix type interface{} has no field or no methods and type assertions example
+41.2k Golang : Convert string to array/slice
+10.1k Golang : Wait and sync.WaitGroup example