Skip to content

distributed-mind/myip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My IP

This is a simple golang module which queries DNS for your requesting IP address. It is much like the web-based services you find when searching for "what is my ip address?" in google. It is based on the information found here.

Example

The returned error will report a "network is unreachable" error if either ipv4 or ipv6 is unavailable.
It will return a "fatal" if both ipv4 and ipv6 are unavailable.

package main

import (
	"fmt"
	"github.com/distributed-mind/myip"
)

func main() {
	ips, err := myip.PublicIPs()
	for _, ip := range ips {
		if len(ip) != 0 {
			fmt.Printf("IP: %v\n", ip.String())
		}
	}
	fmt.Printf("Error: %v\n", err)
}

output from ^example

$ go run example/main.go 
IP: pub.lic.ip.address
Error: ipv6 error: lookup o-o.myaddr.l.google.com on 1.1.1.1:53: dial udp6 [2001:4860:4802:32::a]:53: connect: network is unreachable
$

TODO

  • LAN/internal IP discovery
  • LAN default gateway discovery

Contributing

Please submit an issue or pull request on github.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages