Created
March 8, 2019 08:07
-
-
Save Airr/e8436d1566822475dfe5c84718466634 to your computer and use it in GitHub Desktop.
PublicIP
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
// LINUX - MACOS ONLY | |
package main | |
import ( | |
"fmt" | |
"log" | |
"os/exec" | |
"strings" | |
) | |
//PublicIP - Retrieves public ip address | |
func PublicIP() (string, error) { | |
cmdName := "dig" | |
cmdArgs := strings.Split("+short myip.opendns.com @resolver1.opendns.com", " ") | |
ipAddress, err := exec.Command(cmdName, cmdArgs...).Output() | |
return string(ipAddress), err | |
} | |
func main() { | |
ip, err := PublicIP() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Print(ip) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment