Skip to content

Commit

Permalink
Add function to detect available addresses for dispatching
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjay7178 committed Aug 23, 2024
1 parent a9829e0 commit 1b8d8da
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"net"
)

/*
Detect the addresses which can be used for dispatching in non-tunnelling mode.
Alternate to ipconfig/ifconfig
*/
func detect_interfaces() (map[string]string, error) {
fmt.Println("--- Listing the available adresses for dispatching")
ifaces, _ := net.Interfaces()

if len(ifaces) == 0 {
fmt.Println("No interfaces found")
return nil, nil
}

dict := map[string]string{}

for _, iface := range ifaces {
if (iface.Flags&net.FlagUp == net.FlagUp) && (iface.Flags&net.FlagLoopback != net.FlagLoopback) {
addrs, _ := iface.Addrs()
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
fmt.Printf("[+] %s, IPv4:%s\n", iface.Name, ipnet.IP.String())
dict[iface.Name] = ipnet.IP.String()
}
}
}
}
}
return dict, nil

}

0 comments on commit 1b8d8da

Please sign in to comment.