Created
March 17, 2014 17:37
-
-
Save yinheli/9604273 to your computer and use it in GitHub Desktop.
通过 dnspod 获取本机出口ip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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