Last active
February 24, 2022 00:44
-
-
Save abacigalup-eb/a987a59a0b569b5495d5ead6ac92ed57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
) | |
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