|
@@ -0,0 +1,39 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "log"
|
|
|
+ "net"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ //Create a dummy request
|
|
|
+ publicIp := strings.TrimSpace(getPublicIP())
|
|
|
+ fmt.Println("Your public IP address is: ", publicIp)
|
|
|
+ domains := GetFreeDomain(publicIp)
|
|
|
+ fmt.Println("Your free domain assigned by ISP is: ", domains)
|
|
|
+}
|
|
|
+
|
|
|
+func getPublicIP() string {
|
|
|
+ //http://checkip.amazonaws.com/
|
|
|
+ resp, err := http.Get("http://checkip.amazonaws.com/")
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalln(err)
|
|
|
+ }
|
|
|
+ //We Read the response body on the line below.
|
|
|
+ body, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalln(err)
|
|
|
+ }
|
|
|
+ //Convert the body to type string
|
|
|
+ sb := string(body)
|
|
|
+ return sb
|
|
|
+}
|
|
|
+
|
|
|
+func GetFreeDomain(ipaddr string) []string {
|
|
|
+ ptr, _ := net.LookupAddr(ipaddr)
|
|
|
+ return ptr
|
|
|
+}
|