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
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+8.1k Golang : Tell color name with OpenCV example
+21.2k Golang : Clean up null characters from input data
+5.4k Javascript : How to loop over and parse JSON data?
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+13.1k Golang : How to get a user home directory path?
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+10.7k Golang : Resolve domain name to IP4 and IP6 addresses.
+6.3k Golang : Process non-XML/JSON formatted ASCII text file example
+36.4k Golang : How to split or chunking a file to smaller pieces?
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?