Skip to content

Instantly share code, notes, and snippets.

@abacigalup-eb
Last active February 24, 2022 00:44
Show Gist options
  • Save abacigalup-eb/a987a59a0b569b5495d5ead6ac92ed57 to your computer and use it in GitHub Desktop.
Save abacigalup-eb/a987a59a0b569b5495d5ead6ac92ed57 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net"
)
func main() {
_, vpn, _ := net.ParseCIDR("172.27.0.0/16")
ifaces, err := net.Interfaces()
if err != nil {
panic(err)
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
fmt.Println(err)
continue
}
for _, a := range addrs {
switch v := a.(type) {
case *net.IPNet:
isConnected := vpn.Contains(v.IP)
fmt.Printf("%v : %v | %v\n", i, v, isConnected)
if isConnected {
fmt.Println("CONNECTED!")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment