Skip to content

Instantly share code, notes, and snippets.

@yinheli
Created March 17, 2014 17:37
Show Gist options
  • Save yinheli/9604273 to your computer and use it in GitHub Desktop.
Save yinheli/9604273 to your computer and use it in GitHub Desktop.
通过 dnspod 获取本机出口ip
package main
import (
"fmt"
"net"
"time"
)
func main() {
conn, err := net.DialTimeout("tcp", "ns1.dnspod.net:6666", time.Second*2)
if err != nil {
fmt.Printf("fail dial:%v", err)
return
}
defer conn.Close()
buf := make([]byte, 16)
conn.Read(buf)
fmt.Println("ip:", string(buf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment