musique/server/src/scaner.go

40 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"net"
"time"
)
2022-11-29 21:15:39 +01:00
func scan() []string {
var information []string
ifaces, _ := net.Interfaces()
for _, i := range ifaces {
addrs, _ := i.Addrs()
for _, j := range addrs {
ipv4, _, _ := net.ParseCIDR(j.String())
if ipv4.IsGlobalUnicast() && ipv4.To4() != nil {
ipv4 = ipv4.To4()
ipv4 = ipv4.Mask(ipv4.DefaultMask())
ipv4[3]++
for i := 1; i < 256; i++ {
_, dialErr := net.DialTimeout("tcp", ipv4.String()+":8081", time.Duration(1)*time.Second)
2022-11-29 21:15:39 +01:00
// _, dialErr := net.DialTimeout("tcp", "192.168.0.100:8081", time.Duration(1)*time.Second)
if dialErr != nil {
fmt.Println("Cannot connect to " + ipv4.String())
2022-11-29 21:15:39 +01:00
// fmt.Println("Cannot connect to " + "192.168.0.100:8081")
} else {
fmt.Println("Response from " + ipv4.String())
2022-11-29 21:15:39 +01:00
// fmt.Println("Response from " + "192.168.0.100:8081")
information = append(information, ipv4.String())
// information = append(information, "192.168.0.100:8081")
}
ipv4[3]++
}
}
}
}
return information
}