LoginSignup
0
0

More than 5 years have passed since last update.

Go で IPアドレスから逆引きするには

Posted at

検索しても意外とぱっとは出てこなかったので。お役に立てば幸いです・・・

net.LookupAddr を使う

引数にIPアドレスを指定することで、host が slice で返却されます。

package main

import (
    "fmt"
    "log"
    "net"
)

func main() {
    addr, err := net.LookupAddr("127.0.0.1")
    if err != nil {
        log.Fatal(err)
        return
    }
    fmt.Println(addr)
}
実行結果
[localhost]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0