Post

GoLangGoLang

A
Altaf syed

Posted on 21st February 2024|1716 views

0
votes

Golang Get Ip Address

How can I get an IP address from hostname in Golang?

Answers
P
rushi chowdary

Posted on 21st February 2024

Look at this example

Source sample.go

package main

 import (

   "net"

   "fmt"

)

 func main() {

   add,err := net.LookupIP("ispycode.com")

   if err != nil {

      fmt.Println("host is unknown")

   } else {

      fmt.Println("This is the IP address: ", add)

   }

}

Output:

$go run sample.go

This is the IP address: [80. 75. 225. 3]

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos